feathersjs-ecosystem / feathers-authentication-popups Goto Github PK
View Code? Open in Web Editor NEWServer and client utils for implementing popup-based authentication flows
License: MIT License
Server and client utils for implementing popup-based authentication flows
License: MIT License
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}
Turn the express
middleware into a custom formatter that devs can register.
import oauth2, { popupFormatter } from 'feathers-authentication-oauth2';
import ghStrategy from 'passport-github';
var config = {
formatter: popupFormatter
};
config.Strategy = ghStrategy;
app.configure(oauth2(config, formatter));
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)
}
}
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}
import oauth2, { popupFormatter } from 'feathers-authentication-oauth2';
import ghStrategy from 'passport-github';
var config = {
formatter: popupFormatter
};
config.Strategy = ghStrategy;
app.configure(oauth2(config, formatter));
@marshallswain commented on Wed Dec 14 2016
When there's not a cookie, a blank page sits there staring you in the face.
The parent window won't be available if this is the case. Not sure the best solution to this, but it definitely can't be the blank page that stares back at you when it can't talk to the main window.
Get around popup blockers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.