Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/few-falcons-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@asgardeo/browser': patch
'@asgardeo/express': patch
'@asgardeo/javascript': patch
'@asgardeo/nextjs': patch
'@asgardeo/node': patch
'@asgardeo/react': patch
'@asgardeo/react-router': patch
'@asgardeo/vue': patch
---

Update Sign In
2 changes: 1 addition & 1 deletion packages/express/src/AsgardeoExpressClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

import {LegacyAsgardeoNodeClient, SignOutOptions} from '@asgardeo/node';
import {LegacyAsgardeoNodeClient} from '@asgardeo/node';
import {AsgardeoExpressConfig} from './models/config';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/javascript/src/AsgardeoJavaScriptClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

import {AllOrganizationsApiResponse} from './models/organization';
import {AsgardeoClient, SignInOptions, SignOutOptions, SignUpOptions} from './models/client';
import {Config} from './models/config';
import {AsgardeoClient} from './models/client';
import {Config, SignInOptions, SignOutOptions, SignUpOptions} from './models/config';
import {Storage} from './models/store';
import {EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './models/embedded-flow';
import {EmbeddedSignInFlowHandleRequestPayload} from './models/embedded-signin-flow';
Expand Down
14 changes: 12 additions & 2 deletions packages/javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ export {
EmbeddedFlowExecuteRequestConfig,
} from './models/embedded-flow';
export {FlowMode} from './models/flow';
export {AsgardeoClient, SignInOptions, SignOutOptions, SignUpOptions} from './models/client';
export {BaseConfig, Config, Preferences, ThemePreferences, I18nPreferences, WithPreferences} from './models/config';
export {AsgardeoClient} from './models/client';
export {
BaseConfig,
Config,
Preferences,
ThemePreferences,
I18nPreferences,
WithPreferences,
SignInOptions,
SignOutOptions,
SignUpOptions,
} from './models/config';
export {TokenResponse, IdToken, TokenExchangeRequestConfig} from './models/token';
export {Crypto, JWKInterface} from './models/crypto';
export {OAuthResponseMode} from './models/oauth-response';
Expand Down
5 changes: 1 addition & 4 deletions packages/javascript/src/models/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import {Organization} from './organization';
import {User, UserProfile} from './user';
import {TokenResponse} from './token';
import {Storage} from './store';

export type SignInOptions = Record<string, unknown>;
export type SignOutOptions = Record<string, unknown>;
export type SignUpOptions = Record<string, unknown>;
import {SignInOptions, SignOutOptions, SignUpOptions} from './config';

/**
* Interface defining the core functionality for Asgardeo authentication clients.
Expand Down
51 changes: 51 additions & 0 deletions packages/javascript/src/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ import {I18nBundle} from './i18n';
import {RecursivePartial} from './utility-types';
import {ThemeConfig, ThemeMode} from '../theme/types';

/**
* Interface representing the additional parameters to be sent in the sign-in request.
* This can include custom parameters that your authorization server supports.
* These parameters will be included in the authorization request sent to the server.
* If not provided, no additional parameters will be sent.
*
* @example
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
*/
export type SignInOptions = Record<string, any>;

/**
* Interface representing the additional parameters to be sent in the sign-out request.
* This can include custom parameters that your authorization server supports.
* These parameters will be included in the sign-out request sent to the server.
* If not provided, no additional parameters will be sent.
*
* @example
* signOutOptions: { idTokenHint: "your-id-token-hint" }
*/
export type SignOutOptions = Record<string, unknown>;

/**
* Interface representing the additional parameters to be sent in the sign-up request.
* This can include custom parameters that your authorization server supports.
* These parameters will be included in the sign-up request sent to the server.
* If not provided, no additional parameters will be sent.
*
* @example
* signUpOptions: { appId: "your-app-id" }
*/
export type SignUpOptions = Record<string, unknown>;

export interface BaseConfig<T = unknown> extends WithPreferences {
/**
* Optional URL where the authorization server should redirect after authentication.
Expand Down Expand Up @@ -134,6 +167,24 @@ export interface BaseConfig<T = unknown> extends WithPreferences {
clockTolerance?: number;
};
};

/**
* Optional additional parameters to be sent in the authorize request.
* @see {@link SignInOptions} for more details.
*/
signInOptions?: SignInOptions;

/**
* Optional additional parameters to be sent in the sign-out request.
* @see {@link SignOutOptions} for more details.
*/
signOutOptions?: SignOutOptions;

/**
* Optional additional parameters to be sent in the sign-up request.
* @see {@link SignUpOptions} for more details.
*/
signUpOptions?: SignUpOptions;
}

export interface WithPreferences {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {useRouter} from 'next/navigation';
/**
* Props interface of {@link SignInButton}
*/
export type SignInButtonProps = BaseSignInButtonProps;
export type SignInButtonProps = BaseSignInButtonProps & {
/**
* Additional parameters to pass to the `authorize` request.
*/
signInOptions?: Record<string, any>;
}

/**
* SignInButton component that uses server actions for authentication in Next.js.
Expand Down Expand Up @@ -55,7 +60,7 @@ export type SignInButtonProps = BaseSignInButtonProps;
*/
const SignInButton = forwardRef<HTMLButtonElement, SignInButtonProps>(
(
{className, style, children, preferences, onClick, ...rest}: SignInButtonProps,
{className, style, children, preferences, onClick, signInOptions = {}, ...rest}: SignInButtonProps,
ref: Ref<HTMLButtonElement>,
): ReactElement => {
const {signIn, signInUrl} = useAsgardeo();
Expand All @@ -72,7 +77,7 @@ const SignInButton = forwardRef<HTMLButtonElement, SignInButtonProps>(
if (signInUrl) {
router.push(signInUrl);
} else {
await signIn();
await signIn(signInOptions);
}

if (onClick) {
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/AsgardeoNodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import {AsgardeoJavaScriptClient} from '@asgardeo/javascript';
import {AsgardeoNodeConfig} from './models/config';
import {SignOutOptions} from '@asgardeo/javascript/dist/models/client';

/**
* Base class for implementing Asgardeo in Node.js based applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import useTranslation from '../../../hooks/useTranslation';
/**
* Props interface of {@link SignInButton}
*/
export type SignInButtonProps = BaseSignInButtonProps;
export type SignInButtonProps = BaseSignInButtonProps & {
/**
* Additional parameters to pass to the `authorize` request.
*/
signInOptions?: Record<string, any>;
};

/**
* SignInButton component that supports both render props and traditional props patterns.
Expand Down Expand Up @@ -70,8 +75,8 @@ export type SignInButtonProps = BaseSignInButtonProps;
const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<HTMLButtonElement>> = forwardRef<
HTMLButtonElement,
SignInButtonProps
>(({children, onClick, preferences, ...rest}: SignInButtonProps, ref: Ref<HTMLButtonElement>): ReactElement => {
const {signIn, signInUrl} = useAsgardeo();
>(({children, onClick, preferences, signInOptions: overriddenSignInOptions = {}, ...rest}: SignInButtonProps, ref: Ref<HTMLButtonElement>): ReactElement => {
const {signIn, signInUrl, signInOptions} = useAsgardeo();
const {t} = useTranslation(preferences?.i18n);

const [isLoading, setIsLoading] = useState(false);
Expand All @@ -86,7 +91,7 @@ const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<

window.dispatchEvent(new PopStateEvent('popstate', {state: null}));
} else {
await signIn();
await signIn(overriddenSignInOptions ?? signInOptions);
}

if (onClick) {
Expand Down
13 changes: 12 additions & 1 deletion packages/react/src/contexts/Asgardeo/AsgardeoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import {Context, createContext} from 'react';
import {HttpRequestConfig, HttpResponse, Organization} from '@asgardeo/browser';
import {HttpRequestConfig, HttpResponse, Organization, SignInOptions} from '@asgardeo/browser';
import AsgardeoReactClient from '../../AsgardeoReactClient';

/**
Expand Down Expand Up @@ -79,6 +79,16 @@ export type AsgardeoContextProps = {
*/
requestAll: (requestConfigs?: HttpRequestConfig[]) => Promise<HttpResponse<any>[]>;
};
/**
* Optional additional parameters to be sent in the sign-in request.
* This can include custom parameters that your authorization server supports.
* These parameters will be included in the authorization request sent to the server.
* If not provided, no additional parameters will be sent.
*
* @example
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
*/
signInOptions?: SignInOptions;
};

/**
Expand All @@ -104,6 +114,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
request: () => null,
requestAll: () => null,
},
signInOptions: {},
});

AsgardeoContext.displayName = 'AsgardeoContext';
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
signUpUrl,
organizationHandle,
applicationId,
signInOptions,
...rest
}: PropsWithChildren<AsgardeoProviderProps>): ReactElement => {
const reRenderCheckRef: RefObject<boolean> = useRef(false);
Expand All @@ -81,6 +82,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
scopes,
signUpUrl,
signInUrl,
signInOptions,
...rest,
});

Expand Down Expand Up @@ -393,6 +395,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
request: asgardeo.request.bind(asgardeo),
requestAll: asgardeo.requestAll.bind(asgardeo),
},
signInOptions
}),
[
applicationId,
Expand All @@ -409,6 +412,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
signInSilently,
user,
asgardeo,
signInOptions
],
);

Expand Down
Loading