No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Understanding the Web Server OAuth Authentication Flow
The Web server authentication flow
is used by applications that are hosted on a secure server. A critical
aspect of the Web server flow is that the server must be able to protect
the consumer secret.
In this flow, the client application requests the authorization server to redirect the user to another web server or resource that authorizes the user and sends the application an authorization code. The application uses the authorization code to request an access token. The following shows the steps for this flow.
- The application redirects the user to the appropriate Salesforce authorization
endpoint, such as https://login.salesforce.com/services/oauth2/authorize. The following parameters are required:
The following parameters are optional:An example authorization URL might look something like the following:
1https://login.salesforce.com/services/oauth2/authorize?response_type=code 2&client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0QqEWhqKpoW3svG3X 3HrXDiCQjK1mdgAvhCscA9GE&redirect_uri=https%3A%2F%2Fwww.mysite.com%2F 4code_callback.jsp&state=mystate - The user logs into Salesforce with their credentials. The user is interacting with the authorization endpoint directly, so the application never sees the user’s credentials. After successfully logging in, the user is asked to authorize the application. Note that if the user has already authorized the application, this step is skipped.
- Once Salesforce confirms that the client application is authorized, the end-user’s
Web browser is redirected to the callback URL specified by the redirect_uri parameter. Salesforce appends
authorization information to the redirect URL with the following values:
An example callback URL with authorization information might look something like:
Parameters Description code Authorization code the consumer must use to obtain the access and refresh tokens. state The state value that was passed in as part of the initial request, if applicable. 1https://www.mysite.com/authcode_callback?code=aWekysIEeqM9PiT 2hEfm0Cnr6MoLIfwWyRJcqOqHdF8f9INokharAS09ia7UNP6RiVScerfhc4w%3D%3D - The application extracts the authorization code and passes it
in a request to Salesforce for
an access token. This request is a POST request sent
to the appropriate Salesforce token
request endpoint, such as https://login.salesforce.com/services/oauth2/token. The following parameters are required:
The following parameter is optional:An example access token POST request might look something like:
1POST /services/oauth2/token HTTP/1.1 2Host: login.salesforce.com 3grant_type=authorization_code&code=aPrxsmIEeqM9PiQroGEWx1UiMQd95_5JUZ 4VEhsOFhS8EVvbfYBBJli2W5fn3zbo.8hojaNW_1g%3D%3D&client_id=3MVG9lKcPoNI 5NVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCs 6cA9GE&client_secret=1955279925675241571& 7redirect_uri=https%3A%2F%2Fwww.mysite.com%2Fcode_callback.jsp - If this request is successful, the server returns a response body
that contains the following:
An example JSON response body might look something like:
1{"id":"https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P", 2"issued_at":"1278448101416", 3"refresh_token":"5Aep8614iLM.Dq661ePDmPEgaAW9Oh_L3JKkDpB4xReb54_ 4pZebnUG0h6Sb4KUVDpNtWEofWM39yg==", 5"instance_url":"https://na1.salesforce.com", 6"signature":"CMJ4l+CCaPQiKjoOEwEig9H4wqhpuLSk4J2urAe+fVg=", 7"access_token":"00Dx0000000BV7z!AR8AQP0jITN80ESEsj5EbaZTFG0R 8NBaT1cyWk7TrqoDjoNIWQ2ME_sTZzBjfmOE6zMHq6y8PIW4eWze9JksNEkWUl.Cju7m4"} - The application uses the provided access token and refresh token to access protected user data.