Skip to content

Commit

Permalink
Revert feat: add oidc flow start param (#120) (#129)
Browse files Browse the repository at this point in the history
This reverts commit 44248e3.

## Related Issues
Related to descope/etc#949
  • Loading branch information
guyp-descope authored May 17, 2023
1 parent 1847ef5 commit 1a43b2d
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 83 deletions.
1 change: 0 additions & 1 deletion packages/core-js-sdk/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export type Options = {
deviceInfo?: DeviceInfo;
lastAuth?: LastAuth;
redirectAuth?: RedirectAuth;
oidcIdpStateId?: string;
};

export type ResponseData = Record<string, any>;
Expand Down
1 change: 0 additions & 1 deletion packages/web-component/src/lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME = 'ra-callback';
export const DESCOPE_ATTRIBUTE_PREFIX = 'data-descope-';
export const DESCOPE_ATTRIBUTE_EXCLUDE_FIELD = 'data-exclude-field';
export const DESCOPE_LAST_AUTH_LOCAL_STORAGE_KEY = 'dls_last_auth';
export const OIDC_IDP_STATE_ID_PARAM_NAME = 'state_id';

export const ELEMENT_TYPE_ATTRIBUTE = 'data-type';

Expand Down
2 changes: 0 additions & 2 deletions packages/web-component/src/lib/descope-wc/BaseDescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ class BaseDescopeWc extends HTMLElement {
exchangeError,
redirectAuthCallbackUrl,
redirectAuthCodeChallenge,
oidcIdpStateId,
} = handleUrlParams();

// we want to update the state when user clicks on back in the browser
Expand All @@ -417,7 +416,6 @@ class BaseDescopeWc extends HTMLElement {
telemetryKey: this.telemetryKey,
redirectAuthCallbackUrl,
redirectAuthCodeChallenge,
oidcIdpStateId,
});

this.#debugState.update({ isDebug: this.debug });
Expand Down
3 changes: 0 additions & 3 deletions packages/web-component/src/lib/descope-wc/DescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class DescopeWc extends BaseDescopeWc {
webauthnOptions,
redirectAuthCodeChallenge,
redirectAuthCallbackUrl,
oidcIdpStateId,
} = currentState;

if (this.#currentInterval) {
Expand Down Expand Up @@ -140,7 +139,6 @@ class DescopeWc extends BaseDescopeWc {
{
tenant,
redirectAuth,
oidcIdpStateId,
...(redirectUrl && { redirectUrl }),
},
conditionInteractionId,
Expand Down Expand Up @@ -278,7 +276,6 @@ class DescopeWc extends BaseDescopeWc {
{
tenant,
redirectAuth,
oidcIdpStateId,
lastAuth,
...(redirectUrl && { redirectUrl }),
},
Expand Down
15 changes: 0 additions & 15 deletions packages/web-component/src/lib/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
URL_TOKEN_PARAM_NAME,
URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME,
URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME,
OIDC_IDP_STATE_ID_PARAM_NAME,
} from '../constants';
import { AutoFocusOptions, Direction } from '../types';

Expand Down Expand Up @@ -130,14 +129,6 @@ export function clearRedirectAuthFromUrl() {
resetUrlParam(URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME);
}

export function getOIDCIDPParamFromUrl() {
return getUrlParam(OIDC_IDP_STATE_ID_PARAM_NAME);
}

export function clearOIDCIDPParamFromUrl() {
resetUrlParam(OIDC_IDP_STATE_ID_PARAM_NAME);
}

export const camelCase = (s: string) =>
s.replace(/-./g, (x) => x[1].toUpperCase());

Expand Down Expand Up @@ -216,11 +207,6 @@ export const handleUrlParams = () => {
clearRedirectAuthFromUrl();
}

const oidcIdpStateId = getOIDCIDPParamFromUrl();
if (oidcIdpStateId) {
clearOIDCIDPParamFromUrl();
}

return {
executionId,
stepId,
Expand All @@ -229,7 +215,6 @@ export const handleUrlParams = () => {
exchangeError,
redirectAuthCodeChallenge,
redirectAuthCallbackUrl,
oidcIdpStateId,
};
};

Expand Down
1 change: 0 additions & 1 deletion packages/web-component/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export type FlowState = {
telemetryKey: string;
redirectAuthCodeChallenge: string;
redirectAuthCallbackUrl: string;
oidcIdpStateId: string;
};

export type StepState = {
Expand Down
64 changes: 5 additions & 59 deletions packages/web-component/test/descope-wc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
URL_TOKEN_PARAM_NAME,
URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME,
URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME,
OIDC_IDP_STATE_ID_PARAM_NAME,
} from '../src/lib/constants';
import DescopeWc from '../src/lib/descope-wc';
// eslint-disable-next-line import/no-namespace
Expand Down Expand Up @@ -515,13 +514,7 @@ describe('web-component', () => {
await waitFor(() =>
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
lastAuth: {},
redirectUrl: 'http://custom.url',
oidcIdpStateId: null,
redirectAuth: undefined,
tenant: undefined,
},
{ lastAuth: {}, redirectUrl: 'http://custom.url' },
undefined,
'submitterId',
{
Expand Down Expand Up @@ -1647,12 +1640,7 @@ describe('web-component', () => {
await waitFor(() =>
expect(startMock).toBeCalledWith(
'sign-in',
{
lastAuth: { authMethod: 'otp' },
oidcIdpStateId: null,
redirectAuth: undefined,
tenant: undefined,
},
{ lastAuth: { authMethod: 'otp' } },
conditionInteractionId,
'interactionId',
{ origin: 'http://localhost' },
Expand Down Expand Up @@ -1685,11 +1673,7 @@ describe('web-component', () => {
await waitFor(() =>
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
oidcIdpStateId: null,
redirectAuth: undefined,
tenant: undefined,
},
{},
undefined,
'',
{
Expand Down Expand Up @@ -1753,7 +1737,6 @@ describe('web-component', () => {
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
oidcIdpStateId: null,
redirectAuth: { callbackUrl: callback, codeChallenge: challenge },
tenant: undefined,
},
Expand All @@ -1768,35 +1751,6 @@ describe('web-component', () => {
});
await waitFor(() => expect(window.location.search).toBe(''));
});

it('should call start with oidc idp flag and clear it from url', async () => {
startMock.mockReturnValueOnce(generateSdkResponse());

pageContent = '<span>It works!</span>';

const oidcIdpStateId = 'abcdefgh';
const encodedOidcIdpStateId = encodeURIComponent(oidcIdpStateId);
window.location.search = `?${OIDC_IDP_STATE_ID_PARAM_NAME}=${encodedOidcIdpStateId}`;
document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc flow-id="sign-in" project-id="1"></descope-wc>`;

await waitFor(() =>
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
oidcIdpStateId: 'abcdefgh',
tenant: undefined,
},
undefined,
'',
undefined,
0
)
);
await waitFor(() => screen.findByShadowText('It works!'), {
timeout: 4000,
});
await waitFor(() => expect(window.location.search).toBe(''));
});
});
it('Should call start with code and idpInitiated when idpInitiated condition is met in multiple conditions', async () => {
window.location.search = `?${URL_CODE_PARAM_NAME}=code1`;
Expand Down Expand Up @@ -1825,11 +1779,7 @@ describe('web-component', () => {
await waitFor(() =>
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
oidcIdpStateId: null,
redirectAuth: undefined,
tenant: undefined,
},
{},
undefined,
'',
{
Expand Down Expand Up @@ -1880,11 +1830,7 @@ describe('web-component', () => {
await waitFor(() =>
expect(startMock).toHaveBeenCalledWith(
'sign-in',
{
oidcIdpStateId: null,
redirectAuth: undefined,
tenant: undefined,
},
{},
undefined,
'',
{
Expand Down
2 changes: 1 addition & 1 deletion packages/web-js-sdk/src/sdk/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isSupported } from './webauthn';
type CoreSdkFlowStartArgs = Parameters<CoreSdk['flow']['start']>;
type Options = Pick<
CoreSdkFlowStartArgs[1],
'tenant' | 'redirectUrl' | 'redirectAuth' | 'oidcIdpStateId'
'tenant' | 'redirectUrl' | 'redirectAuth'
> & {
lastAuth?: Omit<CoreSdkFlowStartArgs[1]['lastAuth'], 'loginId' | 'name'>;
};
Expand Down

0 comments on commit 1a43b2d

Please sign in to comment.