Provides a simple way to retrieve an OAuth2 token for API authorization within a Google Chrome Extension.
-
Add the following to your extension manifest:
Note: The
permissions
url andcontent_script
>matches
URL are determined by the API you are requesting authorization for.{ ... ... "permissions":{ "https://github.com/login/oauth/access_token", "tabs" }, "content_scripts":[{ "matches":["https://github.com/robots.txt*"], "js":["libs/chrome-ex-oauth2/injection.js"], "run_at":"document_start" }], ... ... }
-
Add application and API information to
libs/chrome-ex-auth/oauth2.js
:(function() { window.oauth2 = { access_token_url: "{your-access-token-url}", authorization_url: "{your-authorization-url}", client_id: "{your-client-id}", client_secret: "{your-client-secret}", redirect_url: "{your-redirect-url}", scopes: [{your-array-of-scopes}], ... ... })();
-
Include the authorization script in your project:
<html> ... ... <body> ... ... <script src="libs/chrome-ex-oauth/oauth2.js"></script> ... ... </body> </html>
-
To authorize the application from your script:
window.oauth2.start();
-
Include attribution to library.
start()
Starts the authorization process.
getToken()
Retrieves the applications authorization token from the browsers local storage.
clearToken()
Clears the applications token from the browsers local storage.
-- This library has only been tested with the GitHub API v3