1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Use the <code>chrome.identity</code> API to get OAuth2 access tokens. 6 namespace identity { 7 8 dictionary AccountInfo { 9 // A unique identifier for the account. This ID will not change 10 // for the lifetime of the account. 11 DOMString id; 12 }; 13 14 dictionary ProfileUserInfo { 15 // An email address for the user account signed into the current 16 // profile. Empty if the user is not signed in. 17 DOMString email; 18 19 // A unique identifier for the account. This ID will not change 20 // for the lifetime of the account. Empty if the user is not 21 // signed in. 22 DOMString id; 23 }; 24 25 dictionary TokenDetails { 26 // Fetching a token may require the user to sign-in to Chrome, or 27 // approve the application's requested scopes. If the interactive 28 // flag is <code>true</code>, <code>getAuthToken</code> will 29 // prompt the user as necessary. When the flag is 30 // <code>false</code> or omitted, <code>getAuthToken</code> will 31 // return failure any time a prompt would be required. 32 boolean? interactive; 33 34 // The account ID whose token should be returned. If not 35 // specified, the primary account for the profile will be used. 36 // 37 // <code>account</code> is only supported when the 38 // "enable-new-profile-management" flag is set. 39 AccountInfo? account; 40 41 // A list of OAuth2 scopes to request. 42 // 43 // When the <code>scopes</code> field is present, it overrides the 44 // list of scopes specified in manifest.json. 45 DOMString[]? scopes; 46 }; 47 48 dictionary InvalidTokenDetails { 49 // The specific token that should be removed from the cache. 50 DOMString token; 51 }; 52 53 dictionary WebAuthFlowDetails { 54 // The URL that initiates the auth flow. 55 DOMString url; 56 57 // Whether to launch auth flow in interactive mode. 58 // 59 // Since some auth flows may immediately redirect to a result URL, 60 // <code>launchWebAuthFlow</code> hides its web view until the 61 // first navigation either redirects to the final URL, or finishes 62 // loading a page meant to be displayed. 63 // 64 // If the interactive flag is <code>true</code>, the window will 65 // be displayed when a page load completes. If the flag is 66 // <code>false</code> or omitted, <code>launchWebAuthFlow</code> 67 // will return with an error if the initial navigation does not 68 // complete the flow. 69 boolean? interactive; 70 }; 71 72 callback GetAuthTokenCallback = void (optional DOMString token); 73 callback GetAccountsCallback = void (AccountInfo[] accounts); 74 callback GetProfileUserInfoCallback = void (ProfileUserInfo userInfo); 75 callback InvalidateAuthTokenCallback = void (); 76 callback LaunchWebAuthFlowCallback = void (optional DOMString responseUrl); 77 78 interface Functions { 79 // Retrieves a list of AccountInfo objects describing the accounts 80 // present on the profile.<br> 81 // <code>getAccounts</code> is only supported on dev channel. 82 static void getAccounts(GetAccountsCallback callback); 83 84 // Gets an OAuth2 access token using the client ID and scopes 85 // specified in the <a 86 // href="app_identity.html#update_manifest"><code>oauth2</code> 87 // section of manifest.json</a>. 88 // 89 // The Identity API caches access tokens in memory, so it's ok to 90 // call <code>getAuthToken</code> non-interactively any time a token is 91 // required. The token cache automatically handles expiration. 92 // 93 // For a good user experience it is important interactive token requests are 94 // initiated by UI in your app explaining what the authorization is for. 95 // Failing to do this will cause your users to get authorization requests, 96 // or Chrome sign in screens if they are not signed in, with with no 97 // context. In particular, do not use <code>getAuthToken</code> 98 // interactively when your app is first launched. 99 // 100 // |details| : Token options. 101 // |callback| : Called with an OAuth2 access token as specified by the 102 // manifest, or undefined if there was an error. 103 static void getAuthToken(optional TokenDetails details, 104 GetAuthTokenCallback callback); 105 106 // Retrieves email address and obfuscated gaia id of the user 107 // signed into a profile. 108 // 109 // This API is different from identity.getAccounts in two 110 // ways. The information returned is available offline, and it 111 // only applies to the primary account for the profile. 112 static void getProfileUserInfo(GetProfileUserInfoCallback callback); 113 114 // Removes an OAuth2 access token from the Identity API's token cache. 115 // 116 // If an access token is discovered to be invalid, it should be 117 // passed to removeCachedAuthToken to remove it from the 118 // cache. The app may then retrieve a fresh token with 119 // <code>getAuthToken</code>. 120 // 121 // |details| : Token information. 122 // |callback| : Called when the token has been removed from the cache. 123 static void removeCachedAuthToken( 124 InvalidTokenDetails details, InvalidateAuthTokenCallback callback); 125 126 // Starts an auth flow at the specified URL. 127 // 128 // This method enables auth flows with non-Google identity 129 // providers by launching a web view and navigating it to the 130 // first URL in the provider's auth flow. When the provider 131 // redirects to a URL matching the pattern 132 // <code>https://<app-id>.chromiumapp.org/*</code>, the 133 // window will close, and the final redirect URL will be passed to 134 // the <var>callback</var> function. 135 // 136 // For a good user experience it is important interactive auth flows are 137 // initiated by UI in your app explaining what the authorization is for. 138 // Failing to do this will cause your users to get authorization requests 139 // with no context. In particular, do not launch an interactive auth flow 140 // when your app is first launched. 141 // 142 // |details| : WebAuth flow options. 143 // |callback| : Called with the URL redirected back to your application. 144 static void launchWebAuthFlow(WebAuthFlowDetails details, 145 LaunchWebAuthFlowCallback callback); 146 147 // Generates a redirect URL to be used in |launchWebAuthFlow|. 148 // 149 // The generated URLs match the pattern 150 // <code>https://<app-id>.chromiumapp.org/*</code>. 151 // 152 // |path| : The path appended to the end of the generated URL. 153 [nocompile] static DOMString getRedirectURL(optional DOMString path); 154 }; 155 156 interface Events { 157 // Fired when signin state changes for an account on the user's profile. 158 static void onSignInChanged(AccountInfo account, boolean signedIn); 159 }; 160 }; 161