Uber API iOS OAuth 2.0

烂漫一生 提交于 2019-12-01 07:29:51

问题


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?

Here are some references:

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

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


回答1:


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

  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

  4. 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'



来源:https://stackoverflow.com/questions/29460457/uber-api-ios-oauth-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!