Uber API iOS OAuth 2.0

2019-02-19 22:10发布

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条回答
够拽才男人
2楼-- · 2019-02-19 22:50

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'

查看更多
登录 后发表回答