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:
Lauri Ojansivu 2026-02-13 07:19:46 +02:00 committed by GitHub
commit 0db7ab2eaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 23 deletions

View file

@ -1,9 +1,8 @@
"use strict";
const Fiber = Npm.require('fibers');
const https = Npm.require('https');
const url = Npm.require('url');
const xmlParser = Npm.require('xml2js');
import https from 'https';
import url from 'url';
import xml2js from 'xml2js';
// Library
class CAS {
@ -61,7 +60,7 @@ class CAS {
console.log(error);
callback(undefined, false);
} else {
xmlParser.parseString(response, (err, result) => {
xml2js.parseString(response, (err, result) => {
if (err) {
console.log('Bad response format.');
callback({message: 'Bad response format. XML could not parse it'});
@ -120,20 +119,16 @@ let _userData = {};
//RoutePolicy.declare('/_cas/', 'network');
// Listen to incoming OAuth http requests
WebApp.connectHandlers.use((req, res, next) => {
// Need to create a Fiber since we're using synchronous http calls and nothing
// else is wrapping this in a fiber automatically
Fiber(() => {
middleware(req, res, next);
}).run();
});
WebApp.connectHandlers.use(Meteor.bindEnvironment((req, res, next) => {
middleware(req, res, next);
}));
const middleware = (req, res, next) => {
// Make sure to catch any exceptions because otherwise we'd crash
// the runner
let redirectUrl;
try {
urlParsed = url.parse(req.url, true);
const urlParsed = url.parse(req.url, true);
// Getting the ticket (if it's defined in GET-params)
// 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 redirectUrl = serviceUrl;//.replace(/([&?])casToken=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
redirectUrl = serviceUrl;//.replace(/([&?])casToken=[^&]+[&]?/g, '$1').replace(/[?&]+$/g, '');
// get auth token
const credentialToken = query.casToken;
@ -206,7 +201,7 @@ const casValidate = (req, ticket, token, service, callback) => {
* Register a server-side login handle.
* It is call after Accounts.callLoginMethod() is call from client.
*/
Accounts.registerLoginHandler((options) => {
Accounts.registerLoginHandler(async (options) => {
if (!options.cas)
return undefined;
@ -252,13 +247,13 @@ const casValidate = (req, ticket, token, service, callback) => {
if (attrs.debug) {
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 (attrs.debug) {
console.log(`Creating user account ${JSON.stringify(options)}`);
}
const userId = Accounts.insertUserDoc({}, options);
user = Meteor.users.findOne(userId);
const userId = await Accounts.insertUserDoc({}, options);
user = await Meteor.users.findOneAsync(userId);
}
if (attrs.debug) {
console.log(`Using user account ${JSON.stringify(user)}`);
@ -267,7 +262,7 @@ const casValidate = (req, ticket, token, service, callback) => {
});
const _hasCredential = (credentialToken) => {
return _.has(_casCredentialTokens, credentialToken);
return Object.prototype.hasOwnProperty.call(_casCredentialTokens, credentialToken);
}
/*

View file

@ -1,17 +1,17 @@
Package.describe({
summary: "CAS support for accounts",
version: "0.1.0",
version: "0.2.0",
name: "wekan-accounts-cas",
git: "https://github.com/wekan/meteor-accounts-cas"
});
Package.onUse(function(api) {
api.use('ecmascript');
api.use('routepolicy', 'server');
api.use('webapp', 'server');
api.use('accounts-base', ['client', 'server']);
// Export Accounts (etc) to packages using this one.
api.imply('accounts-base', ['client', 'server']);
api.use('underscore');
api.addFiles('cas_client.js', 'web.browser');
api.addFiles('cas_client_cordova.js', 'web.cordova');
api.addFiles('cas_server.js', 'server');