Token Refresh Request
This page is for apps whose app key has been approved by FamilySearch for refresh tokens. Refresh tokens are not generally available for web apps and are not enabled by default. If you have a desktop or mobile app or if your app key has not been approved, see Dev Support.
Refresh Token vs. Token Refresh Request
- A refresh token is a long-lived token that your app saves so it can get new access tokens later. When your app key has been enabled for refresh tokens, FamilySearch returns one alongside the access token at the end of the Authorization Code Flow. Your app stores it securely and never sends it to the FamilySearch API.
- A token refresh is the request your app makes to the token endpoint, using
grant_type=refresh_token, to exchange that refresh token for a new set of tokens without asking the user to log in again.
Refresh tokens are only used by apps acting on behalf of a user who has logged in through the Authorization Code Flow.
Before You Begin
- Your app key must be enabled for refresh tokens. FamilySearch configures this on your app key. App keys are managed separately in Beta and Production, so the key must be enabled in each environment. If your token response does not include
refresh_token, your key has not been enabled in that environment. - Desktop and mobile apps must use PKCE.
- Your app must protect the refresh token. Refresh tokens are long-lived, so store them securely: encrypted on your server, or in your platform's secure storage for desktop and mobile apps (for example, the macOS or iOS Keychain, or Android Keystore). Never expose a refresh token to a browser, include it in client-side code, or write it to logs. If your app can run on shared computers, make sure one user's refresh token can never be used by another user.
Receiving a Refresh Token
Follow the Authorization Code Flow as usual, and include offline_access in the scope parameter of your Authorization Request. Native and mobile apps must also use PKCE.
Example Authorization Request URL (Native/Mobile App with PKCE):
https://ident.familysearch.org/cis-web/oauth2/v3/authorization?client_id=a02f100000SSxKMAA1&redirect_uri=http%3A%2F%2F127.0.0.1%3A57938%2Ffamilysearch-auth&response_type=code&state=237589753&code_challenge=1j_SZ7VLys6EddDGmv6K69OMNgV2KfGG5T4Oaz1cDIE&code_challenge_method=S256&scope=openid%20offline_access
The response to the Token Request will include a refresh_token along with the access_token.
| An access token expires after 60 minutes of inactivity, with a max life of 24 hours. When it expires, use the refresh token to get new tokens, as described below. |
|---|
Token Request with Refresh Token
The Token Request can be made with a Refresh Token to acquire new tokens. This is discussed in Section 6 of the RFC 6749 OAuth 2.0 Spec.
| Parameter | Value |
|---|---|
| grant_type | This must be set to refresh_token. |
| refresh_token | This should be set to the value of your current Refresh Token. |
A successful request will receive a response with a new set of tokens. Your app should discard the used Refresh Token and keep the new token for the next refresh.
Example Request
POST /cis-web/oauth2/v3/token HTTP/1.1
Host: ident.familysearch.org
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=-84169492-45-40-107571079511378-2089-7-1108766-34-4620883010-8022-8110215-4-1-103
Example Response
HTTP/1.1 200 OK
Date: Tue, 03 Nov 2020 22:29:44 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 694
Connection: keep-alive
Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
Content-Encoding: gzip
Content-Language: en-US
Expires: Tue, 03 Jul 2001 06:00:00 GMT
Last-Modified: Tue Nov 03 22:29:44 UTC 2020
Pragma: no-cache
Server: nginx/1.18.0
X-Robots-Tag: noindex, nofollow, noarchive, nosnippet, notranslate, noimageindex
{
"access_token": "your-access-token-here",
"id_token": "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvaW50ZWdyYXRpb24uZmFtaWx5c2VhcmNoLm9yZ1wvc2VydmljZVwvaWRlbnRcL2Npc1wvY2lzLXdlYlwvb2F1dGgyXC92MyIsInN1YiI6ImNpcy51c2VyLk1NTU0tRERIMiIsImF1ZCI6ImEwMmYxMDAwMDBTU3hLTUFBMSIsInNlc3Npb25JZCI6IjgwNjBhYzIxLTcyYzgtNDQ0Yi05ODQ1LWQ5Y2ZkMzFhZjUyNS1pbnRlZyIsImV4cCI6MTYwNDUyNzI0MCwiaWF0IjoxNjA0NTIwMDQwfQ.WvGpCcY1kfi2hvHseJqePmZGrbEMU8tmsSs9IpcvPacuwcevGhIczSGCB_51JdBXMFIicKgowt8lj_k5CYt7ATQjxz1ICiTkvBJsM_xaPcAAkPcN65OKdxxhaStBGypkyrMPDAfP_X3UbXHLJ_EDbG5ffW0JnnM8c-5RIhbhjRLypFEc1kPjLKtlVbOuHt9kPcIkDzzdtiZEQQRnI7nabN9NQbN8bmrv6xexIJgeBAc9iybWMM3x_NsXd9zfKsxPNosjTj0QovAh2JrJSCpHXwimst2YWCe6Rs7PXloI9UDpNcDlPbiwhPdhqpMOIp8zUoGMNeBz0-MUfrElpseqcg",
"refresh_token": "11725-3632127-8773105-8620-58120-97-5086-116117-61-8510384-9058735-50-1217-17826",
"token_type": "Bearer"
}
Using Refresh Tokens
- Detect expiration. When the API returns a 401 response code, your access token has expired.
- Refresh. Make the token refresh request above.
- Rotate. Replace the stored refresh token with the new one from the response. Each refresh token can be used only once.
- Handle failure. If the refresh token has expired or been revoked, the token endpoint returns a
400response with the errorinvalid_grant. Send the user through the Authorization Code Flow again to get new tokens.
Example Error Response
{
"error": "invalid_grant",
"error_description": "The refresh token is invalid or expired."
}Updated about 1 month ago