# OAuth 1.0 Draft
## Authors
* Mark Atwood (me@mark.atwood.name)
* Richard M. Conlan (zeveck@google.com)
* Blaine Cook (blaine@twitter.com)
* Leah Culver (leah@pownce.com)
* Kellan Elliott-McCrea (kellan@yahoo-inc.com)
* Larry Halff (larry@ma.gnolia.com)
* Eran Hammer-Lahav (eran@hueniverse.com)
* Ben Laurie (benl@google.com)
* Chris Messina (chris@citizenagency.com)
* John Panzer (jpanzer@acm.org)
* David Recordon (david@sixapart.com)
* Eran Sandler (eran@yedda.com)
* Jonathan Sergent (sergent@google.com)
* Todd Sieling (todd@ma.gnolia.com)
* Brian Slesinsky (brian-oauth@slesinsky.org)
* Andy Smith (andy@jaiku.com)
## Description
The OAuth protocol enables websites or applications (Consumers) to access Protected Resources from a web service (Service Provider) via an API, without requiring Users to disclose their Service Provider credentials to the Consumers. An example use case is allowing printing service printer.example.com (the Consumer), to access private photos stored on photos.example.net (the Service Provider) without requiring Users to provide their photos.example.net credentials to printer.example.com.
More generally, OAuth creates a freely-implementable and generic methodology for API authentication, benefitting developers who want their Consumer product to interact with various Service Providers.
OAuth does not require a specific user interface or interaction pattern, nor does it specify how Service Providers authenticate Users, making the protocol ideally suited for cases where authentication credentials are unavailable to the Consumer, such as with OpenID.
OAuth aims to unify the experience and implementation of delegated web service authentication into a single, community-driven protocol. OAuth builds on existing protocols and best practices that have been independently implemented by various websites. An open standard, supported by large and small providers alike, promotes a consistent and trusted experience for both application developers and the users of those applications.
## Notation and Conventions
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119]. Domain name examples use [RFC 2606].
## Definitions
* Service Provider
: A web application that allows access via OAuth.
* User
: An individual who has an account with the Service Provider.
* Consumer
: A website or application that uses OAuth to access the Service Provider on behalf of the User.
* Protected Resource(s)
: Data controlled by the Service Provider, which the Consumer can access through authentication.
* Consumer Developer
: An individual or organization that implements a Consumer.
* Consumer Key
: A value used by the Consumer to identify itself to the Service Provider.
* Consumer Secret
: A secret used by the Consumer to establish ownership of the Consumer Key.
* Request Token
: A value used by the Consumer to obtain authorization from the User, and exchanged for an Access Token.
* Access Token
: A value used by the Consumer to gain access to the Protected Resources on behalf of the User, instead of using the User's Service Provider credentials.
* Token Secret
: A secret used by the Consumer to establish ownership of a given Token.
* OAuth Endpoint URLs
: Service Provider URLs used by the Consumer to obtain and exchange Tokens.
* Authorization Endpoint URL
: A Service Provider URL used by the User to grant Consumer access.
* API Endpoint URLs
: Service Provider URLs used by the Consumer to access the Protected Resources.
* OAuth Protocol Parameters
: Parameters with names beginning with `oauth_`.
## Documentation and Registration
OAuth includes a Consumer Key and matching Consumer Secret that together authenticate the Consumer (as opposed to the User) to the Service Provider. Consumer-specific identification allows the Service Provider to vary access levels to Consumers (such as un-throttled API access or other resources).
Service Providers SHOULD NOT rely on the Consumer Secret as a method to verify the Consumer identity, unless the Consumer Secret is known to be inaccessible to anyone other than the Consumer and the Service Provider. Consumer Secrets MAY be an empty string when no Consumer verification is needed.
### Endpoint URLs
All Endpoint URLs for both Service Providers and Consumers MUST include scheme, authority, and path, and MAY include query and fragment as defined by [RFC 3986] section 3. The Endpoint URL query MUST NOT contain any OAuth Protocol Parameters. For example:
http://sp.example.com/authorize
### Service Providers
Service Providers responsibility is to enable Consumer Developers to establish a Consumer Key and Consumer Secret. The process and requirements for provisioning these are entirely up to the Service Providers.
The Service Providers documentation includes:
1. The OAuth Endpoint URLs that the Consumer will use when making OAuth requests.
2. Signature methods supported by the Service Provider.
3. Any additional request parameters that the Service Provider requires in order to obtain a Token. Service Provider specific parameters MUST NOT begin with `oauth_`.
### Consumers
The Consumer Developer MUST establish a Consumer Key and a Consumer Secret with the Service Provider. The Consumer Developer MAY also be required to provide additional information to the Service Provider upon registration.
## Parameters
OAuth Protocol Parameter names and values are case sensitive. Each OAuth Protocol Parameters MUST NOT appear more than once per request, and are REQUIRED unless otherwise noted.
### Parameter Encoding
All parameter names and values are escaped using the [RFC 3986] percent-encoding (%xx) mechanism. Characters not in the unreserved character set ([RFC 3986] section 2.3) MUST be encoded. Characters in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be upper case. Text names and values MUST be encoded as UTF-8 octets before percent-encoding them per [RFC 3629].
unreserved = ALPHA, DIGIT, '-', '.', '_', '~'
### Sending Request Parameters
OAuth Protocol Parameters are sent from the Consumer to the Service Provider in one of three methods, in order of decreasing preference:
1. In the HTTP `Authorization` header as defined in "OAuth HTTP Authorization Scheme".
2. As the HTTP POST request body with a `content-type` of `application/x-www-form-urlencoded`.
3. Added to the URLs in the query part (as defined by [RFC 3986] section 3).
In addition to these defined methods, future extensions may describe alternate methods for sending the OAuth Protocol Parameters.
### OAuth Endpoint URLs Response Parameters
OAuth Endpoint URLs response parameters are sent by the Service Provider to return Tokens and other information to the Consumer in the HTTP response body. The parameter names and values are first encoded as per the "Encoding Parameters" section, and concatenated with the '&' character (ASCII code 38) as defined in [RFC 3986] Section 2.1. For example:
oauth_token=ab3cd9j4ks73hf7g&oauth_token_secret=xyz4992k83j47x0b
### OAuth HTTP Authorization Scheme
This section defines an [RFC 2617] extension to support OAuth. It uses the standard HTTP `Authorization` and `WWW-Authenticate` headers to pass OAuth Protocol Parameters.
It is RECOMMENDED that Service Providers accept the HTTP `Authorization` header. Consumers SHOULD be able to send OAuth Protocol Parameters in the OAuth `Authorization` header.
The extension auth-scheme (as defined by [RFC 2617]) is `OAuth` and is case-insensitive.
#### Authorization Header
The OAuth Protocol Parameters are sent in the `Authorization` header the following way:
1. Parameter names and values are encoded per "Encoding Parameters".
2. For each parameter, the name is immediately followed by an '=' character (ASCII code 61), a '"' character (ASCII code 34), the parameter value (MAY be empty), and another '"' character (ASCII code 34).
3. Parameters are separated by a comma character (ASCII code 44) and OPTIONAL linear whitespace per [RFC 2616].
4. The REQUIRED `realm` parameter is added and interpreted per [RFC 2616], section 1.2. The parameter MAY specify the Authorization Endpoint URL to be used by the Consumer to obtain authorization for the accessed resource.
For example:
Authorization: OAuth realm="https://sp.example.com/oauth/authorize",
oauth_consumer_key="0685bd9184jfhq22",
oauth_token="ad180jjd733klru7",
oauth_signature_method="HMAC-SHA1",
oauth_signature="c0e2483bd0365b9985c038220ef65b4d230afcf6",
oauth_timestamp="137131200",
oauth_nonce="4572616e48616d6d65724c61686176"
#### WWW-Authenticate Header
Service Providers MAY indicate their support for the extension by returning the OAuth HTTP `WWW-Authenticate` header upon API Endpoint URL requests for Protected Resources. As per [RFC 2617] such a response MAY include additional HTTP `WWW-Authenticate` headers:
For example:
WWW-Authenticate: OAuth realm="https://sp.example.com/oauth/authorize"
The realm parameter defines a protection realm per [RFC 2617], section 1.2. The parameter MAY specify the Authorization Endpoint URL to be used by the Consumer to obtain authorization for the accessed resource.
## Authenticating with OAuth
OAuth authentication is the process in which Users grant access to their Protected Resources without sharing their credentials with the Consumer. OAuth uses Tokens generated by the Service Provider instead of the User's credentials in Protected Resources requests. The process uses two Token types:
* Request Token
: Used by the Consumer to ask the User to authorize access to the Protected Resources. The authorized Request Token is exchanged for an Access Token, MUST only be used once, and MUST NOT be used for any other purpose. It is RECOMMENDED that Request Tokens have a limited lifetime.
* Access Token
: Used by the Consumer to access the Protected Resources on behalf of the User. Access Tokens MAY limit access to certain Protected Resources, and MAY have a limited lifetime. Service Providers SHOULD allow Users to revoke Access Tokens. Only the Access Token SHALL be used to access the Protect Resources.
OAuth Authentication is done in three steps:
1. The Consumer obtains an unauthorized Request Token.
2. The User authorizes the Request Token.
3. The Consumer exchanges the Request Token for an Access Token.
### Obtaining an Unauthorized Request Token
The Consumer obtains an unauthorized Request Token by asking the Service Provider to issue a Token. The Request Token's sole purpose is to receive User approval and can only be used to obtain an Access Token. The Request Token process goes as follows:
1. The Consumer requests a Request Token.
2. The Service Provider issues an unauthorized Request Token.
#### 1. Consumer Obtains a Request Token
To obtain a Request Token, the Consumer sends an HTTP GET request to the Service Provider's OAuth Endpoint URL for Request Token requests. The request MUST be signed and contains the following parameters:
* `oauth_consumer_key`
: The Consumer Key.
* `oauth_callback`
: OPTIONAL. The Consumer MAY specify a URL the Service Provider will use to redirect the User back to the Consumer when "Obtaining User Authorization" is complete.
* `oauth_version`
: OPTIONAL. If present, value MUST be `1.0`. Service Providers MUST assume the protocol version to be `1.0` if this parameter is not present. Service Providers’ response to non-`1.0` value is left undefined.
* `oauth_signature_method`
: The signature method the Consumer used to sign the request.
* `oauth_signature`
: The signature as defined in "Signing API Requests".
* `oauth_timestamp`
: As defined in "Nonce and Timestamp".
* `oauth_nonce`
: As defined in "Nonce and Timestamp".
* Any additional parameters, as defined by the Service Provider.
#### 2. Service Provider Issues an Unauthorized Request Token
The Service Provider verifies the signature and Consumer Key and if successful, generates a Request Token and Token Secret and returns them to the Consumer in the HTTP response body as defined in "OAuth Endpoint URLs Response Parameters". The Service Provider MUST ensure the Request Token cannot be exchanged for an Access Token until the User successfully grants access in step 4 below.
The response contains the following parameters:
* `oauth_token`
: The Request Token.
* `oauth_token_secret`
: The Token Secret.
* Any additional parameters, as defined by the Service Provider.
If the request fails verification or is rejected for other reasons, the Service Provider MUST respond with the appropriate response code as defined in "HTTP Response Codes". The Service Provider MAY include some further details about why the request was rejected in the HTTP response body as defined in "OAuth Endpoint URLs Response Parameters".
### Obtaining User Authorization
The Consumer cannot use the Request Token until it has been authorized by the User. Obtaining User authorization includes the following steps:
1. The Consumer directs the User to the Service Provider.
2. The Service Provider authenticates the User and obtains consent.
3. The Service Provider directs the User back to the Consumer.
#### 1. Consumer Directs the User to the Service Provider
In order for the Consumer to be able to exchange the Request Token for an Access Token, the Consumer MUST obtain approval from the User by directing the User to the Service Provider. The Consumer constructs an HTTP GET request to the Service Provider's Authorization Endpoint URL with the following parameter:
* `oauth_token`
: OPTIONAL. The Request Token obtained in the previous step. The Service Provider MAY declare this parameter as REQUIRED, or accept requests to the Authorization Endpoint URL without it, in which case it will prompt the User to enter it manually.
Once the request URL has been constructed the Consumer redirects the User to the URL via the User's web browser. If the Consumer is incapable of automatic HTTP redirection, the Consumer SHALL notify the User how to manually go to the constructed request URL.
Note: If a Service Provider knows a Consumer to be running on a mobile device or set-top box, the Service Provider SHOULD ensure that the Authorization Endpoint URL and Request Token are suitable for manual entry.
#### 2. Service Provider Authenticates the User and Obtains Consent
The Service Provider verifies the User's identity and asks for consent as detailed. OAuth does not specify how the Service Provider authenticates the User. However, it does define a set of REQUIRED steps:
* The Service Provider MUST first verify the User's identity before asking for consent. It MAY prompt the User to sign in if the User has not already done so.
* The Service Provider presents to the User information about the Consumer requesting access (as registered by the Consumer Developer). The information MUST include the duration of the access and the Protected Resources provided. The information MAY include other details specific to the Service Provider.
* The User MUST grant or deny permission for the Service Provider to give the Consumer access to the Protected Resources on behalf of the User. If the User denies the Consumer access, the Service Provider MUST NOT allow access to the Protected Resources.
When displaying any identifying information about the Consumer to the User based on the Consumer Key, the Service Provider MUST inform the User if it is unable to assure the Consumer’s true identity. The method in which the Service Provider informs the User and the quality of the identity assurance is beyond the scope of this specification.
For example, the Consumer Key and Consumer Secret of a desktop application running on a User desktop can be extracted and abused, while a Consumer Key and Consumer Secret stored on a web server behind a firewall is more protected.
#### 3. Service Provider Directs the User Back to the Consumer
After the User authenticates with the Service Provider and grants permission for Consumer access, the Consumer MUST be notified that the Request Token has been authorized and ready to be exchanged for an Access Token. If the User denies access, the Consumer MAY be notified that the Request Token has been revoked.
If the Consumer provided a callback URL in `oauth_callback` (as described in "Consumer Obtains a Request Token"), the Service Provider constructs an HTTP GET request URL, and redirects the User's web browser to that URL with the following parameters:
* `oauth_token`
: The Request Token the User authorized or denied.
The callback URL MAY include Consumer provided query parameters. The Service Provider MUST retain them unmodified and append the `oauth_token` parameter to the existing query.
If no callback URL was provided, the Service Provider instructs the User to manually inform the Consumer that authorization has completed.
### Obtaining an Access Token
The Consumer exchanges the Request Token for an Access Token capable of accessing the Protected Resources. Obtaining an Access Token includes the following steps:
1. The Consumer Requests an Access Token.
2. The Service Provider Grants an Access Token.
#### 1. Consumer Requests an Access Token
The Request Token and Token Secret MUST be exchanged for an Access Token and Token Secret.
To request an Access Token, the Consumer makes an HTTP request to Service Provider OAuth Endpoint URL for Token exchange. The Service Provider documentation MUST specify either HTTP GET or POST for this endpoint. It is RECOMMENDED that this be a POST request. The request MUST be signed per "Signing API Requests", and contains the following parameters:
* `oauth_consumer_key`
: The Consumer Key.
* `oauth_token`
: The Request Token obtained previously.
* `oauth_signature_method`
: The signature method the Consumer used to sign the request.
* `oauth_signature`
: The signature as defined in "Signing API Requests".
* `oauth_timestamp`
: As defined in "Nonce and Timestamp".
* `oauth_nonce`
: As defined in "Nonce and Timestamp".
No additional Service Provider specific parameters are allowed when requesting an Access Token to ensure all Token related information is present prior to seeking User approval.
#### 2. Service Provider Grants an Access Token
The Service Provider exchanges the Consumer's Authorization for a new Access Token and Token Secret. The Service Provider MUST verify that:
* The request is properly signed.
* The Request Token has not been exchanged before for an Access Token.
* The Request Token matches the Consumer Key.
On successful verification, the Service Provider returns an Access Token and a Token Secret in the HTTP response body as defined in "OAuth Endpoint URLs Response Parameters". The Access Token and Token Secret are stored by the Consumer and used when signing Protected Resources requests. The response contains the following parameters:
* `oauth_token`
: The Access Token.
* `oauth_token_secret`
: The Token Secret.
* Any additional parameters, as defined by the Service Provider.
If the request fails verification or is rejected for other reasons, the Service Provider MUST respond with the appropriate response code as defined in "HTTP Response Codes". The Service Provider MAY include some further details about why the request was rejected in the HTTP response body as defined in "OAuth Endpoint URLs Response Parameters".
## Accessing Protected Resources
After successfully receiving the Access Token and Token Secret, the Consumer is able to access the Protected Resources on behalf of the User. The request MUST be signed per "Signing API Requests", and contains the following parameters:
* `oauth_consumer_key`
: The Consumer Key.
* `oauth_token`
: The Access Token.
* `oauth_signature_method`
: The signature method the Consumer used to sign the request.
* `oauth_signature`
: The signature as defined in "Signing API Requests".
* `oauth_timestamp`
: As defined in "Nonce and Timestamp".
* `oauth_nonce`
: As defined in "Nonce and Timestamp".
* Any additional parameters, as defined by the Service Provider.
## Nonce and Timestamp
A nonce is a random string, uniquely generated for each request. The nonce allows the Service Provider to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel (such as HTTP).
The Consumer SHALL first calculate the request timestamp. Unless otherwise specified by the Service Provider, the timestamp is expressed in the number of seconds since January 1, 1970 00:00:00 GMT. The timestamp value MUST be a positive integer and MUST be equal or greater than the timestamp used in previous requests. The Consumer SHALL then generate a Nonce value that is unique for all requests with that timestamp.
## Signing API Requests
The purpose of signing API requests is to prevent unauthorized parties from using the Consumer Key and Tokens when making OAuth Endpoint URL requests or API Endpoint URL requests. The signature process encodes the Consumer Secret and Token Secret into a verifiable value which is included with the request.
OAuth does not mandate a particular signature method, as each API implementation can have its own unique requirements. The protocol defines two signature methods: `HMAC-SHA1`, `PLAINTEXT`, but Service Providers are free to implement and document their own methods. Recommending any particular method is beyond the scope of this specification.
All OAuth Endpoint URL requests and API Endpoint URL requests MUST be signed by the Consumer and verified by the Service Provider. Both the Consumer and Service Provider follow the same process to generate the request signature.
The Consumer declares a signature method in the `oauth_signature_method` parameter, generates a signature, and store it in the `oauth_signature` parameter. The Service Provider verifies the request by generating a new request signature based on the Consumer specified method, and compares it to the signature provided by the Consumer. When verifying a Consumer signature, the Service Provider SHOULD check the request nonce to ensure it has not been used in a previous Consumer request.
The signature process MUST NOT change the request parameter names or values, with the exception of the `oauth_signature` parameter. All request parameters MUST be encoded as described in "Parameter Encoding" prior to applying the signature process.
### Signature Base String
The Signature Base String is a consistent reproducible concatenation of the request elements into a single string. The string is used as an input in hashing or signing algorithms. The `HMAC-SHA1` signature method provides both a standard and an example of using the Signature Base String with a signing algorithm to generate signatures. The process of generating the Signature Base String is as follows:
1. Normalize request parameters
2. Concatenate request elements
#### 1. Normalize Request Parameters
The request parameters are sorted and concatenated into a normalized string. If a request Endpoint contains a query, the query is broken into individual parameters which are also processed. The `oauth_signature` parameter MUST be excluded. The parameters are normalized into a single string as follows:
1. Parameters are sorted by name, using lexicographical byte value ordering. If two or more parameters share the same name, they are sorted by their value. For example: `a=1`, `c=hi%20there`, `f=25`, `f=50`, `z=10`.
2. Parameters are concatenated in their sorted order into a single string. For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61), even if the value is empty. Each name-value pair is separated by an '&' character (ASCII code 38). For example: `a=1&c=hi%20there&f=25&f=50&z=10`.
3. The concatenated string is encoded as described in "Parameter Encoding".
#### 2. Concatenate Request Elements
The following items MUST be concatenated in order into a single string. Each item is separated by an '&' character (ASCII code 38), even if empty.
1. The URL as defined in "Endpoint URLs" excluding the query and fragment parts.
2. The normalized request parameters string from step 1.
3. The HTTP request method used to send the request. Value MUST be uppercase, for example: `HEAD`, `GET`, `POST`, etc.
4. The Consumer Secret, encoded per "Parameter Encoding".
5. The Token Secret, encoded per "Parameter Encoding" (empty value if `oauth_token` is not present).
### HMAC-SHA1
The `HMAC-SHA1` signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC 2104] where the Signature Base String is both the `text` and the `key` and `oauth_signature` is set to the calculated `digest` in HEX string format.
### PLAINTEXT
The `PLAINTEXT` method does not provide any security protection and SHOULD be used over a secure channel such as HTTPS. It does not use the Signature Base String.
`oauth_signature` is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a '.' character (ASCII code 46), even if empty. If the secrets contain a '.' character (ASCII code 46), it must be encoded as `%2E`. The result MUST not be encoded again.
For example, if the Consumer Secret is `dj.9rj$0jd78jf88` and Token Secret is `jjd999(j88ui.hs3`, the encoded values are:
* Consumer Secret
: `dj%2E9rj%240jd78jf88`
* `oauth_token_secret`
: `jjd999%28j88ui%2Ehs3`
And the `oauth_signature` value is `dj%2E9rj%240jd78jf88.jjd999%28j88ui%2Ehs3`. This value is not encoded anymore and is used as it in the HTTP request. If the Token Secret is empty, the value is `dj%2E9rj%240jd78jf88.` (the separator '.' is retained).
## HTTP Response Codes
This section applies only to the Request Token and Access Token OAuth Endpoint URL requests. In general, the Service Provider SHOULD use the response codes defined in [RFC 2616] Section 10. When the Service Provider rejects a Consumer request, it SHOULD respond with HTTP 400 Bad Request or HTTP 401 Unauthorized.
* HTTP 400 Bad Request
* Unsupported parameter
* Unsupported signature method
* Missing required parameter
* Duplicated OAuth Protocol Parameter
* HTTP 401 Unauthorized
* Invalid Consumer Key
* Invalid / expired Token
* Invalid signature
* Invalid / used nonce
## Appendix A – Protocol Example
In this example, the Service Provider photos.example.net is a photo sharing website, and the Consumer printer.example.com is a photo printing website. Jane, the User, would like printer.example.com to print the private photo `vacation.jpg` stored at photos.example.net.
When Jane signs-into photos.example.net using her username and password, she can access the photo by going to the URL `http://photos.example.net/photo?file=vacation.jpg`. Other Users cannot access that photo, and Jane does not want to share her username and password with printer.example.com.
### 1. Documentation and Registration
The Service Provider documentation explains how to register for a Consumer Key and Consumer Secret, and declares the following Endpoint URLs:
* Authorization Endpoint URL
: http://photos.example.net/authorize
* Request Token OAuth Endpoint URL
: https://photos.example.net/request_token
* Access Token OAuth Endpoint URL
: https://photos.example.net/access_token
* Photo (Protected Resource) API Endpoint URL
: http://photos.example.net/photo with required parameter `file` and optional parameter `size`
The Service Provider declares support for the `HMAC-SHA1` signature method for all requests, and `PLAINTEXT` only for secure (HTTPS) requests.
The Consumer printer.example.com already established a Consumer Key and Consumer Secret with photos.example.net and advertizes its printing services for photos stored on photos.example.net. The Consumer registration is:
* Consumer Key
: `dpf43f3p2l4k3l03`
* Consumer Secret
: `kd94hf93k423kf44`
### 2. Obtaining a Request Token
After Jane informs printer.example.com that she would like to print her vacation photo stored at photos.example.net, the printer website tries to access the photo and receives HTTP 401 Unauthorized indicating it is private. The Service Provider includes the following header with the response:
WWW-Authenticate: OAuth realm="http://photos.example.net/authorize"
The Consumer sends the following HTTP GET request to the Service Provider:
https://photos.example.net/request_token?oauth_consumer_key=dpf43f3p2l4k3l03&oauth_callback=http%3A%2f%2fprinter.example.com%2Frequest_token_ready&oauth_version=1.0&oauth_signature_method=PLAINTEXT&oauth_signature=kd94hf93k423kf44.&oauth_timestamp=1191242090&oauth_nonce=hsu94j3884jdopsl
The Service Provider checks the signature and replies with an unauthorized Request Token in the body of the HTTP response:
oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03
### 3. Requesting User Authorization
The Consumer redirects Jane’s browser to the Service Provider Authorization Endpoint URL to obtain Jane’s approval for accessing her private photos.
http://photos.example.net/authorize?oauth_token=hh5s93j4hdidpola
The Service Provider asks Jane to sign-in using her username and password and if successful, asks her if she approves granting printer.example.com access to her private photos. If Jane approves the request, the Service Provider redirects her back to the Consumer’s callback:
http://printer.example.com/request_token_ready?oauth_token=hh5s93j4hdidpola
### 4. Obtaining an Access Token
Now that the Consumer knows Jane approved the Request Token, it asks the Service Provider to exchange it for an Access Token:
https://photos.example.net/access_token?oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=hh5s93j4hdidpola&oauth_signature_method=PLAINTEXT&oauth_signature=kd94hf93k423kf44.hdhd0244k9j7ao03&oauth_timestamp=1191242092&oauth_nonce=dji430splmx33448
The Service Provider checks the signature and replies with an Access Token in the body of the HTTP response:
oauth_token=nnch734d00sl2jdk&oauth_token_secret=pfkkdhi9sl3r4s00
### 5. Accessing Protected Resources
The Consumer is now ready to request the private photo. Since the photo API Endpoint URL is not secure (HTTP), it must use `HMAC-SHA1`. To generate the signature, it first needs to generate the Signature Base String. The request contains the following parameters (`oauth_signature` excluded) which are ordered and concatenated into a normalized string:
* `oauth_consumer_key`
: `dpf43f3p2l4k3l03`
* `oauth_token`
: `nnch734d00sl2jdk`
* `oauth_signature_method`
: `HMAC-SHA1`
* `oauth_timestamp`
: `1191242096`
* `oauth_nonce`
: `kllo9940pd9333jh`
* `file`
: `vacation.jpg`
* `size`
: `original`
The following inputs are used to generate the Signature Base String:
1. The request URL
: `http://photos.example.net/photos`
2. The encoded normalized request parameters string
: `file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26size%3Doriginal`
3. The HTTP request method
: `GET`
4. The Consumer Secret
: `kd94hf93k423kf44`
5. The Token Secret
: `pfkkdhi9sl3r4s00`
The Signature Base String is:
http://photos.example.net/photos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26size%3Doriginal&GET&kd94hf93k423kf44&pfkkdhi9sl3r4s00
HMAC-SHA1 produces the following digest value in HEX string:
9e8004b58fcfb73c0129f6cddaa2d1e4254bac50
All together, the Consumer request for the photo is:
http://photos.example.net/photos?file=vacation.jpg&size=original
Authorization: OAuth realm="http://photos.example.net/authorize",
oauth_consumer_key="dpf43f3p2l4k3l03",
oauth_token="nnch734d00sl2jdk",
oauth_signature_method="HMAC-SHA1",
oauth_signature="9e8004b58fcfb73c0129f6cddaa2d1e4254bac50",
oauth_timestamp="1191242096",
oauth_nonce="kllo9940pd9333jh"
And if using query parameters:
http://photos.example.net/photos?file=vacation.jpg&size=original&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_signature_method=HMAC-SHA1&oauth_signature=9e8004b58fcfb73c0129f6cddaa2d1e4254bac50&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh
photos.example.net checks the signature and responds with the requested photo.
## Appendix B – References
* RFC 2104
: H. Krawczyk, M. Bellare, and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication"
* RFC 2606
: D. Eastlake and A. Panitz, "Reserved Top Level DNS Names"
* RFC 2119
: S. Bradner, "Key words for use in RFCs to Indicate Requirement Levels"
* RFC 2616
: R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee, "Hypertext Transfer Protocol -- HTTP/1.1"
* RFC 2617
: J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. Luotonen, and L. Stewart, "HTTP Authentication: Basic and Digest Access Authentication"
* RFC 3629
: F. Yergeau, "UTF-8, a transformation format of ISO 10646"
* RFC 3986
: T. Berners-Lee, R. Fielding, and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax"