GithubHelp home page GithubHelp logo

oauth2-client's Introduction

Setting up Google Oauth 2

Read https://support.google.com/cloud/answer/6158849?hl=en in order to create Project and Oauth consent screen.

Add users

While the oauth app is in development mode you need to add the users which can access. add users

test the oauth consent app

open the https://developers.google.com/oauthplayground/ google playground select a scope, for initial test you can use google Calendar API

https://www.googleapis.com/auth/calendar

open setting panel and add your keys setting

click on 'Authorize API' you should see the oauth consent screen. At the end you can access

  • Authorization code
  • refresh token
  • access token

Run the example App.

clone https://github.com/donateoa/oauth2-client.git
cd oauth2-client
npm i
ionic serve

you will find the service at http://localhost:8100/

Introduce Oauth2 in your project

1. Add the gapi lib in your project.

<!--Add google calendar api-->
<script src="https://apis.google.com/js/api.js"></script>

2. Initialize the library with your configuration

create an object like this:

 googleCalendarApiConfig: {
    clientId: 'your-client-id.apps.googleusercontent.com',
    scope: 'https://www.googleapis.com/auth/your-scope',
    apiKey: 'your-api-key',
    discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest']
}

replace

  • your-client-id with the clientId from google console
  • your-api-key with the api key from google console

3. initilize the gapi

const { clientId, apiKey, scope, discoveryDocs } = googleCalendarApiConfig;
await gapi.load('client:auth2', async () => {
    this.auth2 = await gapi.client.init({
      apiKey,
      clientId,
      discoveryDocs,
      scope
    });
});

4. handle the authentication state

    // Listen for sign-in state changes.
    gapi.auth2.getAuthInstance().isSignedIn.listen(callbackFunction);

oauth2-client's People

Contributors

donateoa avatar

Watchers

 avatar

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.