This is a GET request which should be made from the client end. A response code will be sent as a GET request to the callback URL.
URL to request for authorization code
https://iris.nitk.ac.in/oauth/authorize
GET Parameters to be sent along
{"client_id":"The Client ID provided to you by IRIS during signup","redirect_uri":"The callback URI to which the token should be sent (The URL must match from one the URLs provided during Oauth Signup with IRIS)","response_type":"code","scope":"<space separated list of scopes you want authorization for from user>"}
Response
code - An access code in order to obtain the actual access token
This response code must be saved somewhere in your backend and/or directly used to immediately obtain the access token from the backend.
Note: This authorization code expires in 10 minutes!
Obtaining the Access Token
After obtaining the code, a server to server request must be made to obtain the access token.
This must be a POST request and should be made from the server backend.
URL to request for authorization code
https://iris.nitk.ac.in/oauth/token
POST Parameters to be sent
{"client_id":"The Client ID provided to you by IRIS during signup","client_secret":"The Client Secret provided to you by IRIS during signup","code":"The authorization code obtained in the above GET request","grant_type":"authorization_code","redirect_uri":"The same redirect URI used in the above GET request"}
Now this access_token can be used for further API queries.
Note: This authorization code expires in 2 hours!
Examples
Note that the client would have to first visit
https://iris.nitk.ac.in/oauth/authorize?client_id=<CLIENT_ID>&redirect_uri=<REDIRECT_URI>&response_type=code&scope=<list of scopes separated by '+'>
in order to get the code from the IRIS authorization server.
Once the client has the code, the steps below can be followed by the client application server to get the access token
Using HTTP Authorization header:
# Ruby# Using HTTP_Authorization Headerrequire'httparty'response=HTTParty.post('https://iris.nitk.ac.in/oauth/token',query: {'grant_type'=>'authorization_code','redirect_uri'=>'<REDIRECT_URI>','code'=>'<access code from the GET request>'},headers: {'Authorization'=>"Basic #{Base64.urlsafe_encode64("<CLIENT_ID>:<CLIENT_SECRET>")}"})putsresponse['access_token']#=> <access_token valid for 2 hours>
// JS// Using HTTP_Authorization Headerconstaxios=require('axios');response=axios.post({'url':'/oauth/token','baseURL':'https://iris.nitk.ac.in/','headers':{'Authorization':`Basic ${btoa('<CLIENT_ID>:<CLIENT_SECRET>')}`},'params':{'grant_type':'authorization_code','redirect_uri':'<REDIRECT_URI>','code':'<access code from the GET request>'}});console.log(response['access_token']);
# Python
# Using HTTP_Authorization Header
importbase64importrequestsresponse=requests.post('https://iris.nitk.ac.in/oauth/token',params={'grant_type':'authorization_code','redirect_uri':'<REDIRECT_URI>','code':'<access code from the GET request>'},headers={'Authorization':'Basic %s'(base64.b64encode(b'<CLIENT_ID>:<CLIENT_SECRET>'))})print(response.text['access_token'])
Using query parameters:
# Ruby# Using query parametersrequire'httparty'response=HTTParty.post('https://iris.nitk.ac.in/oauth/token',query: {'client_id'=>'<CLIENT_ID>','client_secret'=>'<CLIENT_SECRET>','code'=>'<access code from the GET request>','grant_type'=>'authorization_code','redirect_uri'=>'<REDIRECT_URI>'}putsresponse['access_token']
// JS// Using query parametersconstaxios=require('axios');response=axios.post({'url':'/oauth/token','baseURL':'https://iris.nitk.ac.in/','params':{'grant_type':'authorization_code','client_id':'<CLIENT_ID>','client_secret':'<CLIENT_SECRET>','redirect_uri':'<REDIRECT_URI>','code':'<access code from the GET request>'}});console.log(response['access_token']);
# Python
# Using query parameters
importbase64importrequestsresponse=requests.post('https://iris.nitk.ac.in/oauth/token',params={'grant_type':'authorization_code','client_id':'<CLIENT_ID>','client_secret':'<CLIENT_SECRET>','redirect_uri':'<REDIRECT_URI>','code':'<access code from the GET request>'})print(response.text['access_token'])