设计Omniauth和Iphone / Android应用程序 [英] Devise Omniauth and Iphone/Android App

查看:172
本文介绍了设计Omniauth和Iphone / Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Devise和Omniauth的rails应用程序设置了用户权限。
现在我想知道我应该开始使用相同的身份验证Android和iPhone应用程序,我想创建。



我应该使用手机版我/ auth / facebook或者我应该直接从应用程序发送请求?



这是一个非常笼统的问题,但我找不到任何地方。 / p>

编辑:我刚刚向应用程序添加了令牌身份验证,与RESTful api一起使用,我只是丢失了Omniauth / Facebook令牌部分。

解决方案

好的,所以我回答了我自己的问题。



Facebook SDK ,SSO在设备上工作相当不错,但是您收到的令牌与您在Rails应用程序上收到的不一样。显然,Facebook根据支持创建不同的令牌。



所以我做的是:一旦我收到Android设备上的令牌,我将它发送到我的rails应用程序url:

  http:// myapp / check_mobile_login?token = FB_MOBILE_TOKEN 
pre>

然后由我的应用程序控制器捕获,该控制器使用带有fb_graph gem的令牌来获取用户数据。如果令牌有效,我将收到一些信息。然后我查看我的数据库,如果我找到相同的UID,那么我的用户被认证,并且我将其发送给Devise的Authentificable_token。



  def check_mobile_login 
token = params [:token]

user = FbGraph: :user.me(token)
user = user.fetch

logged = User.find_by_uid(user.identifier)

respond_to do | format |
format.html#index.html.erb
format.json {render:json => log.authentication_token}
end
end

如果有人有更好的解决方案,我很高兴听到:)


I've set up user auth for my rails App with Devise and Omniauth. Now I'm wondering where I should start to use the same auth for an Android and iPhone app I want to create.

Should I use a mobile version of my /auth/facebook or should I directly send a request from the app ?

This is a quite general question, but I've found nowhere to look at.

EDIT : I've just added Token Auth to the app to use with the RESTful api, I'm just missing the Omniauth/Facebook-token part.

解决方案

Alright, so I'm answering my own question.

If you use the Facebook SDK, the SSO works quite good on the device, BUT, the token you receive is not the same as the one you're gonna receive on your Rails App. Apparently Facebook creates different tokens depending on the support.

So what I did was: Once I receive the token on the Android device, I send it to my rails app via the url:

http://myapp/check_mobile_login?token=FB_MOBILE_TOKEN

This is then caught by my Application controller, which uses the Token with the fb_graph gem to fetch user data. If the Token is valid I'm going to receive some pieces of information. I then check with my database, and, if I find the same UID, then my user is authenticated and I send him back the Authentificable_token from Devise.

And the draft code :

    def check_mobile_login
        token = params[:token]

        user = FbGraph::User.me(token)
        user = user.fetch

        logged = User.find_by_uid(user.identifier)

        respond_to do |format|
            format.html # index.html.erb
            format.json { render :json => logged.authentication_token }
        end
    end

If anyone has a better solution, I would be glad to hear that :)

这篇关于设计Omniauth和Iphone / Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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