Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
implement oidc discovery
Abdul Rifqi Al Abqary83a20bd7de1b
diff --git a/assets/js/oauth.js b/assets/js/oauth.jsindex 5925b943c..583bae7d5 100644--- a/assets/js/oauth.js+++ b/assets/js/oauth.js@@ -30,6 +30,23 @@ const parseQueryString = string => {segments.forEach(s => queryString[s[0]] = s[1]);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@@ -67,6 +84,7 @@ const pkceChallengeFromVerifier = async(v) => {// Initiate PKCE Auth Code flow when requestedconst tokenRequest = async({+ oidcDiscoveryUrl,grantType,authUrl,accessTokenUrl,@@ -74,6 +92,13 @@ const tokenRequest = async({scope}) => {+ // Check configuration URLs+ if (oidcDiscoveryUrl !== '') {+ const { authorization_endpoint, token_endpoint } = await getTokenConfiguration(oidcDiscoveryUrl);+ authUrl = authorization_endpoint;+ accessTokenUrl = token_endpoint;+ }+// Store oauth informationlocalStorage.setItem('token_endpoint', accessTokenUrl);localStorage.setItem('client_id', clientId);diff --git a/pages/index.vue b/pages/index.vueindex 750212216..05b38a186 100644--- a/pages/index.vue+++ b/pages/index.vue@@ -2455,8 +2455,7 @@ export default {authUrl: this.authUrl,accessTokenUrl: this.accessTokenUrl,clientId: this.clientId,- scope: this.scope,- clientAuth: this.clientAuth+ scope: this.scope};await tokenRequest(tokenReqParams);} catch (e) {