Code Igniter - 使用我自己的 API 和授权 [英] Code Igniter - Consuming my own API and authorisation

查看:21
本文介绍了Code Igniter - 使用我自己的 API 和授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 HMVC codeigniter 安装构建到以 API 为中心的 HMVC(是的,我知道!)

I am attempting to build my HMVC codeigniter install into an API centric HMVC (yeah I know!)

我目前使用 ion_auth 作为授权系统.

I have ion_auth as the authorisation system at the moment.

我设置它的方式是

MODELS
CONTROLLERS 
    - API CONTROLLER
    - CONTROLLER
VIEWS

API 控制器接受 JSON 编码的输入并发送 JSON 编码的输出.

With the API controller accepting JSON encoded inputs and sending JSON encoded outputs.

现在 - 一切正常 -> 我可以通过调用 controller/api 来访问 API,并且可以将它传递给 JSON 并接收 JSON.

Now - it all works fine -> I can access the API by calling controller/api and can pass it JSON and receive JSON back.

然后我只是从我的普通 controller

I then just call the controller/api from within my normal controller

我的问题现在与授权有关.

My problem now comes with authorisation.

如果没有通过 Ion_auth 登录,任何人都无法访问 API(因此它是安全的)但是

Nobody can access the API if they aren't logged in through Ion_auth (so it is secure) BUT

然后我如何公开 API?

How do I then expose the API?

我认为我需要沿着 O Auth 路线走下去,但我已经束手无策,试图弄清楚如何将 O Auth 用于 API 而不会影响性能通过我的控制器访问我的应用程序.

I presume I need to go down the O Auth route but I have tied myself in a knot trying to get my head around how I can use O Auth for the API and not impact the performance of my application when accessed via my controller.

归根结底是不理解 O Auth 是如何完全工作的(我可以实现它并理解握手等,但本质上是坚韧不拔的)-> 如果我找到了某种通过 O Auth 对用户进行身份验证的方法(我的意思是站点用户不是 API 用户)这如何传递到我的控制器 - 它是否存储在会话中?我可以给我的控制器授权吗?(需要吗)

It is down to not understanding how O Auth works fully (I can implement it and understand the hand-shakes etc. but the nitty gritty) -> if I found some way of authenticating a user via O Auth (I mean a site user not an API user) how does this carry through to my controllers - is it stored in a session? Can I give my controllers Authorisations? (Do I need to)

或者 - 有没有一种我没有听说过的 Ion Auth 来做到这一点?

OR - is there a way of doing this with Ion Auth that I haven't heard about?

为了清晰

我希望我自己的应用程序能够使用它自己的 API,但不知道如何设置授权,以便应用程序本身可以直接使用该 API,也可以在本地使用该 API(当用户使用该站点时)

I want my own application to be able to use it's own API, but do not know how to set up the authrosiation so the API can be consumed directly as well as locally by the application itself (when users are using the site)

帮助!!!!!!

提前致谢!

推荐答案

也许您可以删除 API 的 O 身份验证,而只需创建一个访问密钥表.当有人调用 API 时,他需要一个在表中注册的密钥.没有?

Maybe you can remove O auth for the API and just create a table of access key. When someone calls the API he needs a key that registered in the table. No ?

这篇关于Code Igniter - 使用我自己的 API 和授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆