Git Product home page Git Product logo

oauth2-callback-handler's Introduction

OAuth2 Callback Handler ๐Ÿค

OAuth2 Callback Handler is a simple react app for handling callbacks during an OAuth 2.0 Authentication proccess.

Installation

git clone https://github.com/arthursoas/oAuth2-callback-handler.git

cd oAuth2-callback-handler
npm install
npm start

Usage

Set the third party service authentication callback URL as https://oAuth2-callback-handler-host/callback. The OAuth2 Callback Handler will receive the authentication data and post a message to your app with all the parameters sent on URL by the third party sevice you are authenticating.

See the following example:

The service sends the parameters code and user_correlator during the authentication proccess. The callback URL would looks like the following:

https://auth-handler.myapp.com/callback?code=0000000000000&user_correlator=5555555555555

OAuth2 Callback Handler will notify your app with the following message.

{
  code: "0000000000000",
  user_correlator: "5555555555555"
}

To handle that message, you can use the addEventListener method on the page what opened the third party service popup.

Example:

function HandleMessages(message) {
  // Remove message listener after message was received
  window.removeEventListener('message', HandleMessages)
  
  // Do stuff
  // ...
}

window.open(
  "https://auth.third-party-service.com?client_id=99999999&redirect_url=https://oAuth2-callback-handler-host/callback",
  'OAuth Example',
  'height=600,width=500');

// Add a message listener to handle popup messages
window.addEventListener('message', HandleMessages);

Some frameworks can use messages too, so be sure the message received contains the data you are expecting from the OAuth2 Callback Handler

Customization

If you need customize the OAuth2 Callback Handler behavior, create a new module what consumes the CallbackService.

But have in mind that the good pratice is to maintain all your business rules on your application script, and not on the popup. It should be only an intermediary to receive the third party service authentication data and pass it to your application.

oauth2-callback-handler's People

Contributors

dependabot[bot] 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.