Home | History | Annotate | Download | only in api
      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 TokenDetails {
      9     // Fetching a token may require the user to sign-in to Chrome, or
     10     // approve the application's requested scopes. If the interactive
     11     // flag is <code>true</code>, <code>getAuthToken</code> will
     12     // prompt the user as necessary. When the flag is
     13     // <code>false</code> or ommitted, <code>getAuthToken</code> will
     14     // return failure any time a prompt would be required.
     15     boolean? interactive;
     16   };
     17 
     18   dictionary InvalidTokenDetails {
     19     // The specific token that should be removed from the cache.
     20     DOMString token;
     21   };
     22 
     23   dictionary WebAuthFlowDetails {
     24     // The URL that initiates the auth flow.
     25     DOMString url;
     26 
     27     // Whether to launch auth flow in interactive mode.
     28     //
     29     // Since some auth flows may immediately redirect to a result URL,
     30     // <code>launchWebAuthFlow</code> hides its web view until the
     31     // first navigation either redirects to the final URL, or finishes
     32     // loading a page meant to be displayed.
     33     //
     34     // If the interactive flag is <code>true</code>, the window will
     35     // be displayed when a page load completes. If the flag is
     36     // <code>false</code> or ommitted, <code>launchWebAuthFlow</code>
     37     // will return with an error if the initial navigation does not
     38     // complete the flow.
     39     boolean? interactive;
     40   };
     41 
     42   callback GetAuthTokenCallback = void (optional DOMString token);
     43   callback InvalidateAuthTokenCallback = void ();
     44   callback LaunchWebAuthFlowCallback = void (optional DOMString responseUrl);
     45 
     46   interface Functions {
     47     // Gets an OAuth2 access token using the client ID and scopes
     48     // specified in the <a
     49     // href="app_identity.html#update_manifest"><code>oauth2</code>
     50     // section of manifest.json</a>.
     51     //
     52     // The Identity API caches access tokens in memory, so it's ok to
     53     // call <code>getAuthToken</code> any time a token is
     54     // required. The token cache automatically handles expiration.
     55     //
     56     // |details| : Token options.
     57     // |callback| : Called with an OAuth2 access token as specified by the
     58     // manifest, or undefined if there was an error.
     59     static void getAuthToken(optional TokenDetails details,
     60                              GetAuthTokenCallback callback);
     61 
     62     // Removes an OAuth2 access token from the Identity API's token cache.
     63     //
     64     // If an access token is discovered to be invalid, it should be
     65     // passed to removeCachedAuthToken to remove it from the
     66     // cache. The app may then retrieve a fresh token with
     67     // <code>getAuthToken</code>.
     68     //
     69     // |details| : Token information.
     70     // |callback| : Called when the token has been removed from the cache.
     71     static void removeCachedAuthToken(
     72         InvalidTokenDetails details, InvalidateAuthTokenCallback callback);
     73 
     74     // Starts an auth flow at the specified URL.
     75     //
     76     // This method enables auth flows with non-Google identity
     77     // providers by launching a web view and navigating it to the
     78     // first URL in the provider's auth flow. When the provider
     79     // redirects to a URL matching the pattern
     80     // <code>https://<app-id>.chromiumapp.org/*</code>, the
     81     // window will close, and the final redirect URL will be passed to
     82     // the <var>callback</var> function.
     83     //
     84     // |details| : WebAuth flow options.
     85     // |callback| : Called with the URL redirected back to your application.
     86     static void launchWebAuthFlow(WebAuthFlowDetails details,
     87                                   LaunchWebAuthFlowCallback callback);
     88   }
     89   ;
     90 };
     91