OAuth 2 Code Samples
We have created a public repository at github to show how to use Users API and Yottaa OAuth2 Server, you can clone it from here:
https://github.com/Yottaa/api-sample-code
Ruby
Starting with the oauth2 gem is very easy to use the Users API.
client_id = "client_id"
client_secret = "client_secret"
client_url = 'app_url'
client_redirect_url = 'redirect_uri'
client = OAuth2::Client.new(client_id, client_secret, :token_url => '/oauth/access_token', :site =>'https://api.yottaa.com')
Generate the authorization url, you can put the authorize_url in your app's web page, then user can click it and authorize the access to your app.
authorize_url = client.auth_code.authorize_url(:redirect_uri => client_redirect_url, :response_type => 'code')
When user click the authorize_url link in you app web page, the end user will be redirected to https://api.yottaa.com login and authorization page. When all the operations are finished, the end user will be redirected to your client_redirect_url, and you can get the authorization result in this client_redirect_url URL.
If the end user "Deny" the authorization, you will get the response and the workflow is ended here. If the end user "Allow" the authorization, you will get one code, then you can use this code to get the access token:
token_request = client.auth_code.get_token(params[:code], :redirect_uri => client_redirect_url)
token_request.options[:header_format] = "OAuth %s"
token_string = token_request.token
You should save the code and token_string reference to the user, finally you can use the token to access the user's data through the Users API:
request = OAuth2::AccessToken.new client, token_string, :header_format => "OAuth %s"
resp = request.get('/sites')
resp.body
Java
Please refer here https://github.com/Yottaa/api-sample-code
PHP
Please refer here https://github.com/Yottaa/api-sample-code