Coder Social home page Coder Social logo

feathersjs-ecosystem / feathers-authentication-popups Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 2.0 51 KB

Server and client utils for implementing popup-based authentication flows

License: MIT License

JavaScript 100.00%
feathersjs feathers-authentication

feathers-authentication-popups's People

Contributors

bertho-zero avatar corymsmith avatar daffl avatar evanht avatar greenkeeper[bot] avatar marshallswain avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

feathers-authentication-popups's Issues

Integrate with [email protected]

feathers-authentication-client

  • Augment the authenticate method.
app.authenticate({
  strategy: 'github',
  path: '/my/custom/github'
  popup: true
});

Check for popup === true, Use custom path if provided to open popup window, otherwise just prepend, /auth/${strategy}

feathers-authentication-oauth2

Turn the express middleware into a custom formatter that devs can register.

  • add the custom formatter to the package, so they can pass it in.
import oauth2, { popupFormatter } from 'feathers-authentication-oauth2';
import ghStrategy from 'passport-github';

var config = {
  formatter: popupFormatter
};
config.Strategy = ghStrategy;

app.configure(oauth2(config, formatter));

Use postMessage API to work across domains

The express middleware needs to be updated to this:

module.exports = function ({ cookie, targetOrigin }) {
  var cookieName = cookie.name
  if (!cookieName) {
    throw new Error('You must provide a cookie name {String} or an object with a `name` property to the feathers-authentication-popups middleware.')
  }
  var template = `<html>
    <head>
      <script>
        function readCookie(name) {
          var nameEQ = name + "="
          var ca = document.cookie.split(';');
          for(var i=0;i < ca.length;i++) {
            var c = ca[i]
            while (c.charAt(0) === ' ') {
              c = c.substring(1,c.length)
            }
            if (c.indexOf(nameEQ) === 0) {
              return c.substring(nameEQ.length,c.length)
            }
          }
          return null
        }
        var cookieContents = readCookie('${cookieName}')
        if (cookieContents && window.opener) {
          // window.opener.authAgent.emit('login', cookieContents)
          window.opener.postMessage(cookieContents, '${targetOrigin}')
          window.close()
        }
      </script>
    </head>
    <body></body>
  </html>`

  return function (req, res) {
    res.send(template)
  }
}

Integrate with [email protected]

feathers-authentication-client

  • Augment the authenticate method.
app.authenticate({
  strategy: 'github',
  path: '/my/custom/github'
  popup: true
});

Check for popup === true, Use custom path if provided to open popup window, otherwise just prepend, /auth/${strategy}

feathers-authentication-oauth2

  • add the custom formatter to the package, so they can pass it in.
import oauth2, { popupFormatter } from 'feathers-authentication-oauth2';
import ghStrategy from 'passport-github';

var config = {
  formatter: popupFormatter
};
config.Strategy = ghStrategy;

app.configure(oauth2(config, formatter));

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.