chrome.identity
Description: |
Use the chrome.identity API to get OAuth2 access tokens.
|
Availability: |
Since Chrome 35.
|
Permissions: |
"identity"
|
Learn More: |
Identify User
|
Summary
Types | |
---|---|
AccountInfo | |
Methods | |
getAccounts −
chrome.identity.getAccounts(function callback)
| |
getAuthToken −
chrome.identity.getAuthToken(object details, function callback)
| |
getProfileUserInfo −
chrome.identity.getProfileUserInfo(object details, function callback)
| |
removeCachedAuthToken −
chrome.identity.removeCachedAuthToken(object details, function callback)
| |
launchWebAuthFlow −
chrome.identity.launchWebAuthFlow(object details, function callback)
| |
getRedirectURL −
string
chrome.identity.getRedirectURL(string path)
| |
Events | |
onSignInChanged |
Types
AccountInfo
properties | ||
---|---|---|
string | id |
A unique identifier for the account. This ID will not change for the lifetime of the account. |
Methods
getAccounts
chrome.identity.getAccounts(function callback)
Dev channel only. Learn more.
Retrieves a list of AccountInfo objects describing the accounts present on the profile.
getAccounts
is only supported on dev channel.
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(array of AccountInfo accounts) {...};
|
getAuthToken
chrome.identity.getAuthToken(object details, function callback)
Gets an OAuth2 access token using the client ID and scopes specified in the oauth2
section of manifest.json.
The Identity API caches access tokens in memory, so it's ok to call getAuthToken
non-interactively any time a token is required. The token cache automatically handles expiration.
For a good user experience it is important interactive token requests are initiated by UI in your app explaining what the authorization is for. Failing to do this will cause your users to get authorization requests, or Chrome sign in screens if they are not signed in, with with no context. In particular, do not use getAuthToken
interactively when your app is first launched.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) details |
Token options.
|
|||||||||
function | (optional) callback |
Called with an OAuth2 access token as specified by the manifest, or undefined if there was an error. If you specify the callback parameter, it should be a function that looks like this: function(string token) {...};
|
getProfileUserInfo
chrome.identity.getProfileUserInfo(object details, function callback)
Since Chrome 37.
Retrieves email address and obfuscated gaia id of the user signed into a profile.
Requires the identity.email
manifest permission. Otherwise, returns an empty result.
This API is different from identity.getAccounts in two ways. The information returned is available offline, and it only applies to the primary account for the profile.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) details |
Since Chrome 84. Profile options.
|
|||||||||
function | callback |
Called with the The callback parameter should be a function that looks like this: function(object userInfo) {...};
|
removeCachedAuthToken
chrome.identity.removeCachedAuthToken(object details, function callback)
Removes an OAuth2 access token from the Identity API's token cache.
If an access token is discovered to be invalid, it should be passed to removeCachedAuthToken to remove it from the cache. The app may then retrieve a fresh token with getAuthToken
.
Parameters | |||||
---|---|---|---|---|---|
object | details |
Token information.
|
|||
function | (optional) callback |
Called when the token has been removed from the cache. If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
launchWebAuthFlow
chrome.identity.launchWebAuthFlow(object details, function callback)
Starts an auth flow at the specified URL.
This method enables auth flows with non-Google identity providers by launching a web view and navigating it to the first URL in the provider's auth flow. When the provider redirects to a URL matching the pattern https://<app-id>.chromiumapp.org/*
, the window will close, and the final redirect URL will be passed to the callback function.
For a good user experience it is important interactive auth flows are initiated by UI in your app explaining what the authorization is for. Failing to do this will cause your users to get authorization requests with no context. In particular, do not launch an interactive auth flow when your app is first launched.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | details |
WebAuth flow options.
|
||||||
function | callback |
Called with the URL redirected back to your application. The callback parameter should be a function that looks like this: function(string responseUrl) {...};
|
getRedirectURL
string
chrome.identity.getRedirectURL(string path)
Generates a redirect URL to be used in |launchWebAuthFlow|.
The generated URLs match the pattern https://<app-id>.chromiumapp.org/*
.
Parameters | ||
---|---|---|
string | (optional) path |
The path appended to the end of the generated URL. |
Events
onSignInChanged
Fired when signin state changes for an account on the user's profile.
addListener
chrome.identity.onSignInChanged.addListener(function callback)
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function( AccountInfo account, boolean signedIn) {...};
|