mirror of
https://github.com/wekan/wekan.git
synced 2026-02-15 20:48:08 +01:00
Merge pull request #6114 from harryadel/wekan-accounts-cas-async-migration
Migrate wekan-accounts-cas to async API for Meteor 3.0
This commit is contained in:
commit
0db7ab2eaa
3 changed files with 18 additions and 23 deletions
|
|
@ -137,7 +137,7 @@ useraccounts:flow-routing-extra@1.1.0
|
||||||
useraccounts:unstyled@1.14.2
|
useraccounts:unstyled@1.14.2
|
||||||
webapp@1.13.8
|
webapp@1.13.8
|
||||||
webapp-hashing@1.1.1
|
webapp-hashing@1.1.1
|
||||||
wekan-accounts-cas@0.1.0
|
wekan-accounts-cas@0.2.0
|
||||||
wekan-accounts-lockout@1.1.0
|
wekan-accounts-lockout@1.1.0
|
||||||
wekan-accounts-oidc@1.0.10
|
wekan-accounts-oidc@1.0.10
|
||||||
wekan-accounts-sandstorm@0.9.0
|
wekan-accounts-sandstorm@0.9.0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const Fiber = Npm.require('fibers');
|
import https from 'https';
|
||||||
const https = Npm.require('https');
|
import url from 'url';
|
||||||
const url = Npm.require('url');
|
import xml2js from 'xml2js';
|
||||||
const xmlParser = Npm.require('xml2js');
|
|
||||||
|
|
||||||
// Library
|
// Library
|
||||||
class CAS {
|
class CAS {
|
||||||
|
|
@ -61,7 +60,7 @@ class CAS {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
callback(undefined, false);
|
callback(undefined, false);
|
||||||
} else {
|
} else {
|
||||||
xmlParser.parseString(response, (err, result) => {
|
xml2js.parseString(response, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Bad response format.');
|
console.log('Bad response format.');
|
||||||
callback({message: 'Bad response format. XML could not parse it'});
|
callback({message: 'Bad response format. XML could not parse it'});
|
||||||
|
|
@ -120,20 +119,16 @@ let _userData = {};
|
||||||
//RoutePolicy.declare('/_cas/', 'network');
|
//RoutePolicy.declare('/_cas/', 'network');
|
||||||
|
|
||||||
// Listen to incoming OAuth http requests
|
// Listen to incoming OAuth http requests
|
||||||
WebApp.connectHandlers.use((req, res, next) => {
|
WebApp.connectHandlers.use(Meteor.bindEnvironment((req, res, next) => {
|
||||||
// Need to create a Fiber since we're using synchronous http calls and nothing
|
middleware(req, res, next);
|
||||||
// else is wrapping this in a fiber automatically
|
}));
|
||||||
|
|
||||||
Fiber(() => {
|
|
||||||
middleware(req, res, next);
|
|
||||||
}).run();
|
|
||||||
});
|
|
||||||
|
|
||||||
const middleware = (req, res, next) => {
|
const middleware = (req, res, next) => {
|
||||||
// Make sure to catch any exceptions because otherwise we'd crash
|
// Make sure to catch any exceptions because otherwise we'd crash
|
||||||
// the runner
|
// the runner
|
||||||
|
let redirectUrl;
|
||||||
try {
|
try {
|
||||||
urlParsed = url.parse(req.url, true);
|
const urlParsed = url.parse(req.url, true);
|
||||||
|
|
||||||
// Getting the ticket (if it's defined in GET-params)
|
// Getting the ticket (if it's defined in GET-params)
|
||||||
// If no ticket, then request will continue down the default
|
// If no ticket, then request will continue down the default
|
||||||
|
|
@ -150,7 +145,7 @@ const middleware = (req, res, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceUrl = Meteor.absoluteUrl(urlParsed.href.replace(/^\//g, '')).replace(/([&?])ticket=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
|
const serviceUrl = Meteor.absoluteUrl(urlParsed.href.replace(/^\//g, '')).replace(/([&?])ticket=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
|
||||||
const redirectUrl = serviceUrl;//.replace(/([&?])casToken=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
|
redirectUrl = serviceUrl;//.replace(/([&?])casToken=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
|
||||||
|
|
||||||
// get auth token
|
// get auth token
|
||||||
const credentialToken = query.casToken;
|
const credentialToken = query.casToken;
|
||||||
|
|
@ -206,7 +201,7 @@ const casValidate = (req, ticket, token, service, callback) => {
|
||||||
* Register a server-side login handle.
|
* Register a server-side login handle.
|
||||||
* It is call after Accounts.callLoginMethod() is call from client.
|
* It is call after Accounts.callLoginMethod() is call from client.
|
||||||
*/
|
*/
|
||||||
Accounts.registerLoginHandler((options) => {
|
Accounts.registerLoginHandler(async (options) => {
|
||||||
if (!options.cas)
|
if (!options.cas)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
|
|
@ -252,13 +247,13 @@ const casValidate = (req, ticket, token, service, callback) => {
|
||||||
if (attrs.debug) {
|
if (attrs.debug) {
|
||||||
console.log(`CAS response : ${JSON.stringify(result)}`);
|
console.log(`CAS response : ${JSON.stringify(result)}`);
|
||||||
}
|
}
|
||||||
let user = Meteor.users.findOne({ 'username': options.username });
|
let user = await Meteor.users.findOneAsync({ 'username': options.username });
|
||||||
if (! user) {
|
if (! user) {
|
||||||
if (attrs.debug) {
|
if (attrs.debug) {
|
||||||
console.log(`Creating user account ${JSON.stringify(options)}`);
|
console.log(`Creating user account ${JSON.stringify(options)}`);
|
||||||
}
|
}
|
||||||
const userId = Accounts.insertUserDoc({}, options);
|
const userId = await Accounts.insertUserDoc({}, options);
|
||||||
user = Meteor.users.findOne(userId);
|
user = await Meteor.users.findOneAsync(userId);
|
||||||
}
|
}
|
||||||
if (attrs.debug) {
|
if (attrs.debug) {
|
||||||
console.log(`Using user account ${JSON.stringify(user)}`);
|
console.log(`Using user account ${JSON.stringify(user)}`);
|
||||||
|
|
@ -267,7 +262,7 @@ const casValidate = (req, ticket, token, service, callback) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const _hasCredential = (credentialToken) => {
|
const _hasCredential = (credentialToken) => {
|
||||||
return _.has(_casCredentialTokens, credentialToken);
|
return Object.prototype.hasOwnProperty.call(_casCredentialTokens, credentialToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
Package.describe({
|
Package.describe({
|
||||||
summary: "CAS support for accounts",
|
summary: "CAS support for accounts",
|
||||||
version: "0.1.0",
|
version: "0.2.0",
|
||||||
name: "wekan-accounts-cas",
|
name: "wekan-accounts-cas",
|
||||||
git: "https://github.com/wekan/meteor-accounts-cas"
|
git: "https://github.com/wekan/meteor-accounts-cas"
|
||||||
});
|
});
|
||||||
|
|
||||||
Package.onUse(function(api) {
|
Package.onUse(function(api) {
|
||||||
|
api.use('ecmascript');
|
||||||
api.use('routepolicy', 'server');
|
api.use('routepolicy', 'server');
|
||||||
api.use('webapp', 'server');
|
api.use('webapp', 'server');
|
||||||
api.use('accounts-base', ['client', 'server']);
|
api.use('accounts-base', ['client', 'server']);
|
||||||
// Export Accounts (etc) to packages using this one.
|
// Export Accounts (etc) to packages using this one.
|
||||||
api.imply('accounts-base', ['client', 'server']);
|
api.imply('accounts-base', ['client', 'server']);
|
||||||
api.use('underscore');
|
|
||||||
api.addFiles('cas_client.js', 'web.browser');
|
api.addFiles('cas_client.js', 'web.browser');
|
||||||
api.addFiles('cas_client_cordova.js', 'web.cordova');
|
api.addFiles('cas_client_cordova.js', 'web.cordova');
|
||||||
api.addFiles('cas_server.js', 'server');
|
api.addFiles('cas_server.js', 'server');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue