IOS的foursquare oauth2 [英] foursquare oauth2 for IOS

查看:150
本文介绍了IOS的foursquare oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将v1从foursquare api升级到v2需要Oauth2。

是否正确使用Web服务器流程,我建议将用户引导至:
https://foursquare.com/oauth2/authenticate
?client_id = YOUR_CLIENT_ID
& response_type = code
& redirect_uri = YOUR_REGISTERED_REDIRECT_URI

一旦用户通过验证,foursquare将重定向到:
https:// YOUR_REGISTERED_REDIRECT_URI /?code = CODE



含义我需要在 https:// YOUR_REGISTERED_REDIRECT_URI ,然后它会向

https://foursquare.com/oauth2/access_token
?client_id = YOUR_CLIENT_ID
& client_secret = YOUR_CLIENT_SECRET
& grant_type = authorizati on_code
& redirect_uri = YOUR_REGISTERED_REDIRECT_URI
& code = CODE



可以在我的服务器端获得实际的令牌。

这个流程如何将令牌传回移动设备使用?

感谢您的帮助。

解决方案

这仅仅是我的一部分,但是这里有一个可能的流程:


  1. 打开uiwebview并将用户发送至 https://foursquare.com/ oauth2 / authenticate ?client_id = YOUR_CLIENT_ID& response_type = code& redirect_uri = YOUR_REGISTERED_REDIRECT_URI

  2. 接受后,他们将被重定向到 https:// YOUR_REGISTERED_REDIRECT_URI /?code = CODE ,例如 https://domainyouown.com/callback?code=asdfasdfasdfasdf

  3. 您有回电页面向 https://foursquare.com/oauth2/access_token ?client_id = YOUR_CLIENT_ID& client_secret = YOUR_CLIENT_SECRET& grant_type = authorization_code& amp ; redirect_uri = YOUR_REGISTERED_REDIRECT_URI& code = CODE

  4. 获取json响应(仍然在您的回调页面代码中),将其保存到您的serverside db(如果正在使用中) (b)使用UIWebView的 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)脚本来获取div的值,并在div中使用id为'oauth-token'的页面。将它存储在您的iphone设置中

您可能还想查看 https://github.com/nxtbgthng/OAuth2Client


Im upgrading from v1 foursquare api to v2 which requires Oauth2.

Is it correct that to use the web server flow as recommened I should direct the user to : https://foursquare.com/oauth2/authenticate ?client_id=YOUR_CLIENT_ID &response_type=code &redirect_uri=YOUR_REGISTERED_REDIRECT_URI

Once the user is authenticated foursquare will redirect to : https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE

Meaning I need to define an endpoint at https://YOUR_REGISTERED_REDIRECT_URI which will then make a request to

https://foursquare.com/oauth2/access_token ?client_id=YOUR_CLIENT_ID &client_secret=YOUR_CLIENT_SECRET &grant_type=authorization_code &redirect_uri=YOUR_REGISTERED_REDIRECT_URI &code=CODE

to get the actual token on my serverside.

How does this flow get the token back to the mobile device for usage?

Thanks for the help.

解决方案

This is just a guess my part, but here's a possible flow:

  1. open a uiwebview and send the user to https://foursquare.com/oauth2/authenticate ?client_id=YOUR_CLIENT_ID &response_type=code &redirect_uri=YOUR_REGISTERED_REDIRECT_URI
  2. after they accept, they will get redirected to https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE such as https://domainyouown.com/callback?code=asdfasdfasdfasdf
  3. have you callback page make a request to https://foursquare.com/oauth2/access_token ?client_id=YOUR_CLIENT_ID &client_secret=YOUR_CLIENT_SECRET &grant_type=authorization_code &redirect_uri=YOUR_REGISTERED_REDIRECT_URI &code=CODE
  4. get the json response (still in your callback page code), save it to your serverside db (if in use), and also display on the html of the page in a div with an id of 'oauth-token'.
  5. use UIWebView's - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script to get the value of the div and store it in your iphone settings

You may also want to check out https://github.com/nxtbgthng/OAuth2Client

这篇关于IOS的foursquare oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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