OAuth 2.0 php to get access token


(Info Enum) #1

I am unable to generate access token via OAuth 2.0 in php, can you please give me some example code and simple procedure for it, because in documentation its very confusing, So please help me.

Thanks
Mohd Umar


PHP SDK, Get Token
(Dnote Mobile) #2

First of all, you need to make sure you defined your application, defined your OAuth Redirect url and have your Dwolla key and secret.

I use Chrome and Postman (https://www.getpostman.com/) for these steps and then store the access token object in our database, but you can easily code these steps in PHP.

These are the steps for the sandbox environment:

  1. Enter this in the browser:
    https://uat.dwolla.com/oauth/v2/authenticate?client_id=<YOUR CLIENT KEY>&response_type=code&redirect_uri=<YOUR OAUTH REDIRECT URL>&scope=Transactions%7CSend%7CFunding%7CBalance%7CAccountInfoFull%7CScheduled%7CManageAccount%7CRequest%7CEmail
  • use your client key, your OAuth redirect URL and define whatever scopes you need
  1. Dwolla calls your OAuth redirect URL and attaches a code
  • IMPORTANT, this code is only valid for a short time. Maybe 60 seconds
  • example response: https://my.oauth.redirect?code=XqvPFyBURTEZEezURpXLBMJMgKVG
  1. Make a POST request to get an access token using the code from Step 2
POST https://uat.dwolla.com/oauth/v2/token
{
"client_id": <YOUR CLIENT KEY>,
"client_secret": <YOUR CLIENT SECRET>,
"code": "XqvPFyBURTEZEezURpXLBMJMgKVG",
"grant_type": "authorization_code",
"redirect_uri": <YOUR OAUTH REDIRECT URL>
}
  1. Dwolla returns your access token object

Access tokens are only good for about an hour so you’ll need a process to update your access token using the refresh_token returned in the access token object.


(Anton Logvinenko) #3

I have the same issue with PHP. I can’t get access token. The only way to get access token is to make POST request with x-www-form-urlencoded Content-Type and with parameters described in Step 3. After that request I get page in Dwolla domain https://uat.dwolla.com/oauth/v2/token with json data. How can I get this data into my app? There is redirect_uri parameter on Step 3 and it is not working. No redirect. I thought it should redirect back to my redirect_uri URL.

So I’ve tried to make request with cURL. The idea is to make POST request with cURL, parse JSON and get an access token into my app. The result - “You should enable cookies”. Even If I enable cookies with cURL. I guess there is Cloudflare protection with javascript logic makes this is impossible.

Also I’ve tried to make this request with AJAX. The issue there is Cross-Domain request that blocked with browser policy. In case if uat.dwolla.com would allow Cross-Domain requests with special headers in response it could work, but no headers from Dwolla.

So, few days with authorization issue. Please help me.