Coder Social home page Coder Social logo

chrome-ex-oauth2's Introduction

Chrome Extension OAuth2 Library

Provides a simple way to retrieve an OAuth2 token for API authorization within a Google Chrome Extension.

How To Use

  1. Add the following to your extension manifest:

    Note: The permissions url and content_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"
    	}],
    	
    	...
    	...
    }
    
  2. 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}],
    		
    		...
    		...
    	
    	})();			
    		
  3. Include the authorization script in your project:

    <html>
    ...
    ...
    <body>
    	...
    	...
    	
    	<script src="libs/chrome-ex-oauth/oauth2.js"></script>
    	
    	...
    	...
    </body>
    </html>
  4. To authorize the application from your script:

    window.oauth2.start();
  5. Include attribution to library.

API

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

chrome-ex-oauth2's People

Contributors

jjnford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chrome-ex-oauth2's Issues

Where do I get tokens?

In step 2, you outline that I need to have these tokens:

        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}],

Do you know the best way to get these? What if my extension doesn't have a redirect url, or I am working in development mode?

what if my client secret has exposed?

this implementation looks great.
but I have a question.
chrome extension is distributed in ZIP with javascript source inside.
is there any way to avoid my client secret being exposed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.