-
Notifications
You must be signed in to change notification settings - Fork 1
Authentication
-
Register an oauth client and store your secret safely.
-
Setup a link to the endpoint
/oauth2/authorizewith theGETparametersclient_id,response_typeandredirect_uri. The link may look like this: The API will now handle the authentication and return to the givenREDIRECT_URI. Note that for security reasons theREDIRECT_URIhas to be added to the list ofREDIRECT_URISon the oauth client settings.<a href={ API_URL + "/oauth2/authorize?client_id=" + CLIENT_ID + "&response_type=code&redirect_uri=" + REDIRECT_URI}> Login </a> -
The API will now redirect the user to the given
REDIRECT_URIwith theGETparametercode. This parameter contains the authentication code that your application needs in order to obtain an access token. With this code and your client secret, you can now send aPOSTrequest the the endpoint/oauth2/tokenwith the parametersclientId,clientSecret,codeandgrant_type. If you want to get an access token (which you most probably want), set the parametergrant_typetoauthorization_code. On success, this will return a json object containing the keyaccess_token. This key refers to an object containing the keystoken(The access token itself),clientId,userIdandexpires. Note: This shouldn't be an ajax request in the users browser, as your clients secret will be exposed that way. -
Store this token and now you're ready to go. In order to make an api call on the users behalf, add the HTTP header
Authorizationwith the contentBearer {token}(without the curly braces). When using anXMLHttpRequest, this can be done by executinghttp.setRequestHeader("Authorization", "Bearer " + accessToken);.