Old version
Register client app with Authorization Server (Twitter, Google, …).
You gets:
consumer_key (public identifier)consumer_secret (private secret, never share, always in backend)Client app send a request to Authorization Server to get the request token:
POST /oauth/request_token
Authorization: OAuth
oauth_consumer_key="YOUR_CONSUMER_KEY",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="CURRENT_UNIX_TIMESTAMP",
// random string to prevent replay
oauth_nonce="RANDOM_STRING",
oauth_version="1.0",
// computed using consumer_secret and request parameters
oauth_signature="SIGNATURE"
Get the request token from Authorization Server.
Client send the user to the Authorization URL:
<https://authserver.com/oauth/authorize?oauth_token=REQUEST_TOKEN>
User login to the Authorization Server, accept permission to allow accessing the data on client app.
Authorization Server redirects back to client app callback URL:
<https://yourapp.com/callback?oauth_token=REQUEST_TOKEN&oauth_verifier=VERIFIER>
The oauth_verifier is at the query param, it is one-time code to exchange for access token.
Client app send request to Authorization Server to exchange request token for Access Token:
POST /oauth/access_token
Authorization: OAuth
oauth_consumer_key="YOUR_CONSUMER_KEY",
oauth_token="REQUEST_TOKEN",
oauth_verifier="VERIFIER",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="CURRENT_TIMESTAMP",
oauth_nonce="RANDOM_STRING",
oauth_version="1.0",
oauth_signature="SIGNATURE"
Authorization server return
// used to access resources
oauth_token=ACCESS_TOKEN
// used to sign requests (nvr share, always in backend)
oauth_token_secret=ACCESS_TOKEN_SECRET
// optional info:
user_id=12345
screen_name=johndoe
Now client app can call protected api endpoint
GET /api/user/profile
Authorization: OAuth
oauth_consumer_key="YOUR_CONSUMER_KEY",
oauth_token="ACCESS_TOKEN",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="CURRENT_TIMESTAMP",
oauth_nonce="RANDOM_STRING",
oauth_version="1.0",
// now uses consumer_secret + access_token_secret to sign
oauth_signature="SIGNATURE"