Overview
The browser and mobile web implementations of Sign in with X are based on OAuth. This page demonstrates the requests needed to obtain an access token for the sign in flow. To use the “Sign in with X flow, please go to your X app settings and ensure that the “Allow this app to be used to Sign in with X?” option is enabled. This page assumes that the reader knows how to sign requests using the OAuth 1.0a protocol. If you want to know how to sign a request, read the Authorizing a request page. If you want to check the signing of the requests on this page, the consumer secret used is:Step 1: Obtaining a request token
To start a sign-in flow, your X app must obtain a request token by sending a signed message to POST oauth / request_token. The only unique parameter in this request isoauth_callback, which must be a URL-encoded version of the URL you wish your user to be redirected to when they complete step 2. The remaining parameters are added by the OAuth signing process.
Please note - Any callback URL that you use with the POST oauth / request_token endpoint will have to be whitelisted within the X app settings in the developer console.
Example request (Authorization header has been wrapped):
200 indicates a failure. The body of the response will contain the oauth_token, oauth_token_secret, and oauth_callback_confirmed parameters. Your app should verify that oauth_callback_confirmed is true and store the other two values for the next steps.
Example response (response body has been wrapped):
Step 2: Redirecting the user
The next step is to direct the user to X so that they may complete the appropriate flow, as described in Browser sign-in flow. Direct the user to GET oauth / authenticate, and the request token obtained in step 1 should be passed as theoauth_token parameter.
The most seamless way for a website to implement this would be to issue an HTTP 302 redirect as the response to the original “sign in” request. Mobile and desktop apps should open a new browser window or direct to the URL via an embedded web view.
Example URL to redirect to:
- Signed in and approved: If the user is signed in on x.com and has already approved the calling application, they will be immediately authenticated and returned to the callback URL with a valid OAuth request token. The redirect to x.com is not obvious to the user.
- Signed in but not approved: If the user is signed in to x.com but has not approved the calling application, a request to share access with the calling application will be shown. After accepting the authorization request, the user will be redirected to the callback URL with a valid OAuth request token.
- Not signed in: If the user is not signed in on x.com, they will be prompted to enter their credentials and grant access for the application to access their information on the same screen. Once signed in, the user will be returned to the callback URL with a valid OAuth request token.
callback_url would receive a request containing the oauth_token and oauth_verifier parameters. Your application should verify that the token matches the request token received in step 1.
Request from client’s redirect (querystring parameters wrapped):
Step 3: Converting the request token to an access token
To render the request token into a usable access token, your application must make a request to the POST oauth / access_token endpoint, containing theoauth_verifier value obtained in step 2. The request token is also passed in the oauth_token portion of the header, but this will have been added by the signing process.
Example request (Authorization header wrapped):
oauth_token, oauth_token_secret parameters. The token and token secret should be stored and used for future authenticated requests to the X API. To determine the identity of the user, use GET account / verify_credentials.