Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small wrapper around openid-client passport for integrating with Grean EasyID
"use strict";
const { Issuer, Strategy } = require("openid-client");
Issuer.defaultHttpOptions = { timeout: 5000 };
function createUser(userinfo) {
const name = userinfo.name.split(",");
return {
id: userinfo.uniqueuserid,
provider: "grean",
socialno: userinfo.socialno,
name: {
familyName: name[0],
givenName: name[1].substr(1),
},
displayName: userinfo.name,
};
}
class PassportGrean {
constructor({ issuerUrl, clientId, clientSecret, redirectUri }) {
this.issuerUrl = issuerUrl;
this.clientId = clientId;
this.clientSecret = clientSecret;
this.redirectUri = redirectUri;
this.init();
}
init() {
this.issuer = new Issuer({
issuer: this.issuerUrl,
authorization_endpoint: `${this.issuerUrl}/oauth2/authorize`,
token_endpoint: `${this.issuerUrl}/oauth2/token`,
userinfo_endpoint: `${this.issuerUrl}/oauth2/userinfo`,
jwks_uri: `${this.issuerUrl}/.well-known/jwks`,
});
this.client = new this.issuer.Client({
client_id: this.clientId,
client_secret: this.clientSecret,
});
}
createStrategy() {
return new Strategy(
{
client: this.client,
params: { redirect_uri: this.redirectUri },
},
(tokenset, userinfo, done) => {
done(null, createUser(userinfo));
},
);
}
}
module.exports = PassportGrean;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.