Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log("Could not retrieve oidc configuration for oidc provider " + providerKey);
process.exit(1);
} else {
if(!response.data || !response.data.issuer || !response.data.token_endpoint || !response.data.authorization_endpoint || !response.data.jwks_uri)
{
console.log("Response from oidc provider does not contain expected values " + response);
process.exit(1);
}
provider.issuer = response.data.issuer;
provider.token_endpoint = response.data.token_endpoint;
provider.authorization_endpoint = response.data.authorization_endpoint;
provider.jwks_uri = response.data.jwks_uri;
let issuer = new Issuer({
issuer: provider.issuer,
authorization_endpoint: provider.authorization_endpoint,
token_endpoint: provider.token_endpoint,
jwks_uri: provider.jwks_uri
}); // => Issuer
console.log('Set up issuer %s %O', issuer.issuer, issuer.metadata);
provider.client = new issuer.Client({
client_id: provider.client_id,
client_secret: provider.client_secret
});
axios({
method: 'get',
url: provider.jwks_uri,
if (protocol === 'openid') {
if (endSessionUrl) {
issuerParams.end_session_endpoint = endSessionUrl
}
if (jwks || jwksUrl) {
issuerParams.jwks_uri = jwksUrl || getJwksUrl({ publicPlatformId, provider, serverPort })
}
if (idTokenSignedResponseAlg) { // node-openid-client default: 'RS256'
issuerParams.id_token_signed_response_alg = idTokenSignedResponseAlg
}
if (tokenEndpointAuthSigningAlg) {
issuerParams.token_endpoint_auth_signing_alg = tokenEndpointAuthSigningAlg
}
}
const issuer = new Issuer(issuerParams)
const client = new issuer.Client({
client_id: clientId,
client_secret: clientSecret || null,
response_types: ['code']
})
return client
}
const { Issuer } = require('openid-client');
const express = require('express');
const session = require('express-session');
const app = express();
const port = 3000;
app.use(session({
secret: '123456',
resave: true,
saveUninitialized: true
}));
Issuer.defaultHttpOptions = { timeout: 15000 }
const issuer = new Issuer({
issuer: process.env.APPID_ISSUER,
authorization_endpoint: process.env.APPID_AUTHORIZATION_ENDPOINT,
token_endpoint: process.env.APPID_TOKEN_ENDPOINT,
userinfo_endpoint: process.env.APPID_USERINFO_ENDPOINT,
jwks_uri: process.env.APPID_JWKS_URI,
});
console.log('Issuer %s %O', issuer.issuer, issuer.metadata);
issuer.defaultHttpOptions = { timeout: 15000 }
const client = new issuer.Client({
client_id: process.env.APPID_CLIENTID,
client_secret: process.env.APPID_SECRET
});
let authorizationUrl = client.authorizationUrl({
redirect_uri: process.env.REDIRECT_URL_CALLBACK,
private getIssuer = async () => {
if (this.issuer) {
return this.issuer;
}
this.issuer = (!isEmpty(this.issuerConfig))
? new Issuer(this.issuerConfig)
: await Issuer.discover(this.discoveryUrl);
return this.issuer;
}
const plugin = this;
const cache = plugin.server.cache;
const discover_url = plugin.config.issuer.discover_url;
const cache_key = "issuer:" + plugin.server.utils.md5(discover_url);
let issuer;
issuer = cache.get(cache_key);
if (issuer !== undefined) {
return issuer;
}
if (discover_url) {
issuer = await Issuer.discover(discover_url);
cache.set(cache_key, issuer, ISSUER_CACHE_DURATION);
return issuer;
} else {
issuer = new Issuer(plugin.config.issuer);
plugin.server.logger.verbose(
"manual issuer %s %O",
issuer.issuer,
issuer.metadata
);
cache.set(cache_key, issuer, ISSUER_CACHE_DURATION);
return issuer;
}
}
private getIssuer = async () => {
if (this.issuer) {
return this.issuer;
}
const issuerConfig = get(this.oidc, 'issuerConfig');
const discoveryUrl = get(this.oidc, 'discoveryUrl');
this.issuer = (!isEmpty(issuerConfig))
? new Issuer(issuerConfig)
: await Issuer.discover(discoveryUrl);
return this.issuer;
}
oauthStrategy.userProfile = function (accessToken, done) {
debug(`userProfile(${this.authMethodId})`);
if (authMethodConfig.retrieveProfile) {
debug(`userProfile(${this.authMethodId}): Retrieve userProfile from profileEndpoint`);
let issuer = new Issuer({
issuer: "IdP Issuer",
authorization_endpoint: authMethodConfig.endpoints.authorizeEndpoint,
token_endpoint: authMethodConfig.endpoints.tokenEndpoint,
userinfo_endpoint: authMethodConfig.endpoints.profileEndpoint
});
let client = new issuer.Client({
client_id: authMethodConfig.clientId,
client_secret: authMethodConfig.clientSecret,
redirect_uris: [callbackUrl],
response_types: ['code']
});
client.userinfo(accessToken)
.then(function (userInfo) {
debug(`retrieveUserProfileCallback: Successfully retrieved profile from endpoint`);
done(null, userInfo);
})
private getIssuer = async () => {
if (this.issuer) {
return this.issuer;
}
this.issuer = (!isEmpty(this.issuerConfig))
? new Issuer(this.issuerConfig)
: await Issuer.discover(this.discoveryUrl);
return this.issuer;
}