简体   繁体   English

如果我已经具有access_token,如何获取omniauth哈希?

[英]How to get omniauth hash if I already have the access_token?

Currently I have it implemented like so. 目前,我已经像这样实现了。

def auth_hash
    url = URI.parse('https://graph.facebook.com/me')

    url.query = URI.encode_www_form('access_token' => @token, 'fields' => 'email, name, first_name, last_name, gender')
    req = Net::HTTP::Get.new url.request_uri

    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    response = nil
    http.start do |get|
      response = get.request(req)
    end
    response
end

My IOS app does the callbacks and sends the access token to authenticated with our server. 我的IOS应用程序执行回调,并将访问令牌发送到已通过我们的服务器验证的身份。

I use the method above and it returns the hash from the graph api and I get the user info perfectly. 我使用上面的方法,它从图形api返回哈希值,并且可以完美地获得用户信息。

This method that I've used but it's not utilizing omniauth. 我曾经使用过这种方法,但是没有利用omniauth。 So my question is there a way to retrieve the omniauth hash using only the generated access_token (the token is generated by the facebook sdk and sends it to the server)? 所以我的问题是有一种方法可以仅使用生成的access_token(令牌由facebook sdk生成并将其发送到服务器)来检索omniauth哈希吗?

I'm just trying to make sure I'm not reinventing the wheel using this method. 我只是想确保我不会使用这种方法重新发明轮子。

There are few ruby gems for authentication with Facebook and retrieving data from it. 很少有红宝石可以通过Facebook进行身份验证并从中检索数据。

Please refer this link : https://github.com/arsduo/koala , https://github.com/nov/fb_graph2 请参考此链接: https : //github.com/arsduo/koala,https : //github.com/nov/fb_graph2

And for google use can use refer this link: https://github.com/zquestz/omniauth-google-oauth2 对于Google,可以使用此链接: https : //github.com/zquestz/omniauth-google-oauth2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从omniauth回调响应中获取access_token? - How do I get the access_token from the omniauth callback response? 当用户已经登录时,如何使用Twitter gem和Omniauth gem获取用户的访问令牌? - How do I fetch the access token for a user using the Twitter gem and the Omniauth gem when the users is already logged in? 如何在删除用户帐户时重置omniauth-google-oauth2 access_token - How to reset omniauth-google-oauth2 access_token when user account has been removed 如何在ruby on rails中获取access_token instagram api? - how to get access_token instagram api in ruby on rails? 如何通过devise omniauth-osm获取OpenStreetMap访问令牌 - How to get OpenStreetMap access token with devise omniauth-osm Rails:如何检查access_token是否已过期? - Rails: How can I check if the access_token is expired? 无法使用Devise,Rails 4从Omniauth身份验证策略中检索access_token,refresh_token - Can't retrieve access_token, refresh_token from Omniauth authentication strategy with Devise, Rails 4 如何处理Omniauth中的访问令牌(来自Auth Hash)? - What to do with access token(from the Auth Hash) in Omniauth? Rails + OmniAuth Facebook:如何获取Access Token? - Rails + OmniAuth Facebook: how to obtain Access Token? 尝试从Google OAuth 2.0获取access_token时为什么会出现404错误? - Why do I get a 404 Error when attempting to get an access_token from google OAuth 2.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM