优步API iOS OAuth 2.0 [英] Uber API iOS OAuth 2.0

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

问题描述

我试图创建一个iOS,它将使用优步API来做游戏等等。我试图在iPhone上实现OAuth 2.0而不使用任何服务器端帮助。

I was trying to make a iOS which will use the Uber API to do things like get rides and what not. I am trying to implement the OAuth 2.0 on the iPhone without using any server side help.

这可能吗?有没有人这样做过?

Is that possible? Has anyone done this?

以下是一些参考资料:

Uber身份验证: https://developer.uber.com/v1/auth/

Uber Authentication: https://developer.uber.com/v1/auth/

Oauth 2.0: https://aaronparecki.com/articles/2012/ 07/29/1 / oauth2-simplified

Oauth 2.0: https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified

推荐答案

是的,这是可能的。我能够使用Uber API为我的应用配置OAuth2。以下是分步说明:

Yes, this is possible. I was able to configure OAuth2 for my app using Uber API. Here are step-by-step instructions:


  1. 在您的应用中,重定向到 response_type = code 进行com / oauth / authorizerel =noreferrer> https://login.uber.com/oauth/authorize 订单允许用户授权您的应用。

  2. 成功授权后,优步将重定向到您的 redirect_uri (您可以指定任何redirect_uri,包括localhost:xxxx用于测试目的等)为您提供一次性使用且有效10分钟的身份验证代码。实现回调以检索此身份验证代码。

  3. 使用步骤2中的有效身份验证代码,发出POST请求以交换访问令牌。作为一个简单的检查,我建议使用curl来确认访问令牌的有效性。例如:
    curl -F'client_secret = YOUR_CLIENT_SECRET'\
    -F'client_id = YOUR_CLIENT_ID'\
    -F'grant_type = authorization_code'\
    -F'redirect_uri = YOUR_REDIRECT_URI'\
    -F'code = AUTHORIZATION_CODE'\
    https://login.uber.com/oauth/token

  1. In your app, redirect to https://login.uber.com/oauth/authorize with your client_id and response_type=code in order to allow user to authorize your app.
  2. Upon successful authorization, Uber will redirect to your redirect_uri (you can specify any redirect_uri, including localhost:xxxx for testing purposes, etc.) to provide you with an auth code that is single-use and valid for 10 min. Implement a callback to retrieve this auth code.
  3. With the valid auth code from Step 2, make a POST request to exchange for an access token. As a simple check, I would recommend using curl to confirm access token validity. For ex: curl -F 'client_secret=YOUR_CLIENT_SECRET' \ -F 'client_id=YOUR_CLIENT_ID' \ -F 'grant_type=authorization_code' \ -F 'redirect_uri=YOUR_REDIRECT_URI' \ -F 'code=AUTHORIZATION_CODE' \ https://login.uber.com/oauth/token

成功交换后,使用访问令牌作为后续端点调用的授权标头的值。例如:
curl -H'授权:Bearer YOUR_ACCESS_TOKEN''https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823'

Upon successful exchange, use the access token as the value for the 'Authorization' header for subsequent endpoint calls. For ex: curl -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' 'https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823'

这篇关于优步API iOS OAuth 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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