Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support PhantAuth authentication #5850

Merged
merged 3 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/AuthenticationAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const responses = {
wechat: { errcode: 0 },
weibo: { uid: 'userId' },
qq: 'callback( {"openid":"userId"} );', // yes it's like that, run eval in the client :P
phantauth: { sub: 'userId' },
};

describe('AuthenticationProviders', function() {
Expand All @@ -33,6 +34,7 @@ describe('AuthenticationProviders', function() {
'spotify',
'wechat',
'weibo',
'phantauth',
].map(function(providerName) {
it('Should validate structure of ' + providerName, done => {
const provider = require('../lib/Adapters/Auth/' + providerName);
Expand Down
2 changes: 2 additions & 0 deletions src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const qq = require('./qq');
const wechat = require('./wechat');
const weibo = require('./weibo');
const oauth2 = require('./oauth2');
const phantauth = require('./phantauth');

const anonymous = {
validateAuthData: () => {
Expand Down Expand Up @@ -47,6 +48,7 @@ const providers = {
qq,
wechat,
weibo,
phantauth,
};

function authDataValidator(adapter, appIds, options) {
Expand Down
46 changes: 46 additions & 0 deletions src/Adapters/Auth/phantauth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Helper functions for authenticating with PhantAuth.
*
* PhantAuth was designed to simplify testing for applications using OpenID Connect
* authentication by making use of random generated users.
*
* To learn more, please go to: https://wwww.phantauth.net
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.phantauth.net, you have an extra w

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanx, fixed

*/

var Parse = require('parse/node').Parse;
const httpsRequest = require('./httpsRequest');

// Returns a promise that fulfills if this user id is valid.
function validateAuthData(authData) {
return request('auth/userinfo', authData.access_token).then(data => {
if (data && data.sub == authData.id) {
return;
}
throw new Parse.Error(
dplewis marked this conversation as resolved.
Show resolved Hide resolved
Parse.Error.OBJECT_NOT_FOUND,
'PhantAuth auth is invalid for this user.'
);
});
}

// Returns a promise that fulfills iff this app id is valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanx, fixed

function validateAppId() {
return Promise.resolve();
}

// A promisey wrapper for api requests
function request(path, access_token) {
return httpsRequest.get({
host: 'phantauth.net',
path: '/' + path,
headers: {
Authorization: 'bearer ' + access_token,
'User-Agent': 'parse-server',
},
});
}

module.exports = {
validateAppId: validateAppId,
validateAuthData: validateAuthData,
};