implement oidc discovery
This commit is contained in:
@@ -30,6 +30,23 @@ const parseQueryString = string => {
|
|||||||
segments.forEach(s => queryString[s[0]] = s[1]);
|
segments.forEach(s => queryString[s[0]] = s[1]);
|
||||||
return queryString;
|
return queryString;
|
||||||
}
|
}
|
||||||
|
// Get OAuth configuration from OpenID Discovery endpoint
|
||||||
|
const getTokenConfiguration = async endpoint => {
|
||||||
|
const options = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch(endpoint, options);
|
||||||
|
const config = await response.json();
|
||||||
|
return config;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Request failed', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// PKCE HELPER FUNCTIONS
|
// PKCE HELPER FUNCTIONS
|
||||||
@@ -67,6 +84,7 @@ const pkceChallengeFromVerifier = async(v) => {
|
|||||||
|
|
||||||
// Initiate PKCE Auth Code flow when requested
|
// Initiate PKCE Auth Code flow when requested
|
||||||
const tokenRequest = async({
|
const tokenRequest = async({
|
||||||
|
oidcDiscoveryUrl,
|
||||||
grantType,
|
grantType,
|
||||||
authUrl,
|
authUrl,
|
||||||
accessTokenUrl,
|
accessTokenUrl,
|
||||||
@@ -74,6 +92,13 @@ const tokenRequest = async({
|
|||||||
scope
|
scope
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
// Check configuration URLs
|
||||||
|
if (oidcDiscoveryUrl !== '') {
|
||||||
|
const { authorization_endpoint, token_endpoint } = await getTokenConfiguration(oidcDiscoveryUrl);
|
||||||
|
authUrl = authorization_endpoint;
|
||||||
|
accessTokenUrl = token_endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
// Store oauth information
|
// Store oauth information
|
||||||
localStorage.setItem('token_endpoint', accessTokenUrl);
|
localStorage.setItem('token_endpoint', accessTokenUrl);
|
||||||
localStorage.setItem('client_id', clientId);
|
localStorage.setItem('client_id', clientId);
|
||||||
|
|||||||
@@ -2455,8 +2455,7 @@ export default {
|
|||||||
authUrl: this.authUrl,
|
authUrl: this.authUrl,
|
||||||
accessTokenUrl: this.accessTokenUrl,
|
accessTokenUrl: this.accessTokenUrl,
|
||||||
clientId: this.clientId,
|
clientId: this.clientId,
|
||||||
scope: this.scope,
|
scope: this.scope
|
||||||
clientAuth: this.clientAuth
|
|
||||||
};
|
};
|
||||||
await tokenRequest(tokenReqParams);
|
await tokenRequest(tokenReqParams);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user