Skip to content

Commit

Permalink
Merge pull request #2728 from Hyperkid123/use-redirect-uri
Browse files Browse the repository at this point in the history
Use stored redirect_uri in getOfflineToken requests.
  • Loading branch information
Hyperkid123 authored Dec 11, 2023
2 parents 68846ef + 5bf8994 commit 321b7a2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/auth/OIDCConnector/OIDCSecured.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { login, logout } from './utils';
import createGetUserPermissions from '../createGetUserPermissions';
import initializeAccessRequestCookies from '../initializeAccessRequestCookies';
import { getOfflineToken, prepareOfflineRedirect } from '../offline';
import { OFFLINE_REDIRECT_STORAGE_KEY } from '../../utils/consts';

type Entitlement = { is_entitled: boolean; is_trial: boolean };
const serviceAPI = entitlementsApi();
Expand Down Expand Up @@ -94,12 +95,14 @@ export function OIDCSecured({
},
getToken: () => Promise.resolve(authRef.current.user?.access_token ?? ''),
getRefreshToken: () => Promise.resolve(authRef.current.user?.refresh_token ?? ''),
getOfflineToken: () =>
getOfflineToken(
getOfflineToken: () => {
const redirectUri = new URL(localStorage.getItem(OFFLINE_REDIRECT_STORAGE_KEY) || `${window.location.origin}${window.location.pathname}`);
return getOfflineToken(
authRef.current.settings.metadata?.token_endpoint ?? '',
authRef.current.settings.client_id,
encodeURIComponent((authRef.current.settings.metadata?.token_endpoint ?? '').split('#')[0])
),
encodeURIComponent(redirectUri.toString().split('#')[0])
);
},
doOffline: () => login(authRef.current, ['offline_access'], prepareOfflineRedirect()),
getUser: () => Promise.resolve(mapOIDCUserToChromeUser(authRef.current.user ?? {}, {})),
token: authRef.current.user?.access_token ?? '',
Expand Down

0 comments on commit 321b7a2

Please sign in to comment.