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

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

问题描述

我已经使用 Devise 和 Omniauth 为我的 rails 应用程序设置了用户身份验证.现在我想知道我应该从哪里开始对我想要创建的 Android 和 iPhone 应用程序使用相同的身份验证.

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.

我应该使用我的/auth/facebook 的移动版本还是应该直接从应用程序发送请求?

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.

我刚刚将令牌身份验证添加到应用程序以与 RESTful api 一起使用,我只是缺少 Omniauth/Facebook 令牌部分.

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.

如果您使用 Facebook SDK,则 SSO 在设备上运行良好,但是,您收到的令牌与您将在 Rails 应用程序上收到的令牌不同.显然,Facebook 根据支持创建了不同的代币.

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.

所以我所做的是:在 Android 设备上收到令牌后,我通过以下网址将其发送到我的 rails 应用程序:

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

这随后被我的应用程序控制器捕获,它使用带有 fb_graph gem 的令牌来获取用户数据.如果令牌有效,我将收到一些信息.然后我检查我的数据库,如果我找到相同的 UID,那么我的用户通过身份验证,我从 Devise 向他发送 Authentificable_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.

以及代码草案:

    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天全站免登陆