Skip to content

Commit c2dc64d

Browse files
authored
Merge pull request #119 from brionmario/feat-addtional-auth-params
Feat addtional auth params
2 parents 275b244 + ad71f09 commit c2dc64d

File tree

11 files changed

+112
-18
lines changed

11 files changed

+112
-18
lines changed

.changeset/few-falcons-boil.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@asgardeo/browser': patch
3+
'@asgardeo/express': patch
4+
'@asgardeo/javascript': patch
5+
'@asgardeo/nextjs': patch
6+
'@asgardeo/node': patch
7+
'@asgardeo/react': patch
8+
'@asgardeo/react-router': patch
9+
'@asgardeo/vue': patch
10+
---
11+
12+
Update Sign In

packages/express/src/AsgardeoExpressClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* under the License.
1717
*/
1818

19-
import {LegacyAsgardeoNodeClient, SignOutOptions} from '@asgardeo/node';
19+
import {LegacyAsgardeoNodeClient} from '@asgardeo/node';
2020
import {AsgardeoExpressConfig} from './models/config';
2121

2222
/**

packages/javascript/src/AsgardeoJavaScriptClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
import {AllOrganizationsApiResponse} from './models/organization';
20-
import {AsgardeoClient, SignInOptions, SignOutOptions, SignUpOptions} from './models/client';
21-
import {Config} from './models/config';
20+
import {AsgardeoClient} from './models/client';
21+
import {Config, SignInOptions, SignOutOptions, SignUpOptions} from './models/config';
2222
import {Storage} from './models/store';
2323
import {EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './models/embedded-flow';
2424
import {EmbeddedSignInFlowHandleRequestPayload} from './models/embedded-signin-flow';

packages/javascript/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,18 @@ export {
7575
EmbeddedFlowExecuteRequestConfig,
7676
} from './models/embedded-flow';
7777
export {FlowMode} from './models/flow';
78-
export {AsgardeoClient, SignInOptions, SignOutOptions, SignUpOptions} from './models/client';
79-
export {BaseConfig, Config, Preferences, ThemePreferences, I18nPreferences, WithPreferences} from './models/config';
78+
export {AsgardeoClient} from './models/client';
79+
export {
80+
BaseConfig,
81+
Config,
82+
Preferences,
83+
ThemePreferences,
84+
I18nPreferences,
85+
WithPreferences,
86+
SignInOptions,
87+
SignOutOptions,
88+
SignUpOptions,
89+
} from './models/config';
8090
export {TokenResponse, IdToken, TokenExchangeRequestConfig} from './models/token';
8191
export {Crypto, JWKInterface} from './models/crypto';
8292
export {OAuthResponseMode} from './models/oauth-response';

packages/javascript/src/models/client.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ import {Organization} from './organization';
2727
import {User, UserProfile} from './user';
2828
import {TokenResponse} from './token';
2929
import {Storage} from './store';
30-
31-
export type SignInOptions = Record<string, unknown>;
32-
export type SignOutOptions = Record<string, unknown>;
33-
export type SignUpOptions = Record<string, unknown>;
30+
import {SignInOptions, SignOutOptions, SignUpOptions} from './config';
3431

3532
/**
3633
* Interface defining the core functionality for Asgardeo authentication clients.

packages/javascript/src/models/config.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ import {I18nBundle} from './i18n';
2020
import {RecursivePartial} from './utility-types';
2121
import {ThemeConfig, ThemeMode} from '../theme/types';
2222

23+
/**
24+
* Interface representing the additional parameters to be sent in the sign-in request.
25+
* This can include custom parameters that your authorization server supports.
26+
* These parameters will be included in the authorization request sent to the server.
27+
* If not provided, no additional parameters will be sent.
28+
*
29+
* @example
30+
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
31+
*/
32+
export type SignInOptions = Record<string, any>;
33+
34+
/**
35+
* Interface representing the additional parameters to be sent in the sign-out request.
36+
* This can include custom parameters that your authorization server supports.
37+
* These parameters will be included in the sign-out request sent to the server.
38+
* If not provided, no additional parameters will be sent.
39+
*
40+
* @example
41+
* signOutOptions: { idTokenHint: "your-id-token-hint" }
42+
*/
43+
export type SignOutOptions = Record<string, unknown>;
44+
45+
/**
46+
* Interface representing the additional parameters to be sent in the sign-up request.
47+
* This can include custom parameters that your authorization server supports.
48+
* These parameters will be included in the sign-up request sent to the server.
49+
* If not provided, no additional parameters will be sent.
50+
*
51+
* @example
52+
* signUpOptions: { appId: "your-app-id" }
53+
*/
54+
export type SignUpOptions = Record<string, unknown>;
55+
2356
export interface BaseConfig<T = unknown> extends WithPreferences {
2457
/**
2558
* Optional URL where the authorization server should redirect after authentication.
@@ -134,6 +167,24 @@ export interface BaseConfig<T = unknown> extends WithPreferences {
134167
clockTolerance?: number;
135168
};
136169
};
170+
171+
/**
172+
* Optional additional parameters to be sent in the authorize request.
173+
* @see {@link SignInOptions} for more details.
174+
*/
175+
signInOptions?: SignInOptions;
176+
177+
/**
178+
* Optional additional parameters to be sent in the sign-out request.
179+
* @see {@link SignOutOptions} for more details.
180+
*/
181+
signOutOptions?: SignOutOptions;
182+
183+
/**
184+
* Optional additional parameters to be sent in the sign-up request.
185+
* @see {@link SignUpOptions} for more details.
186+
*/
187+
signUpOptions?: SignUpOptions;
137188
}
138189

139190
export interface WithPreferences {

packages/nextjs/src/client/components/actions/SignInButton/SignInButton.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import {useRouter} from 'next/navigation';
2727
/**
2828
* Props interface of {@link SignInButton}
2929
*/
30-
export type SignInButtonProps = BaseSignInButtonProps;
30+
export type SignInButtonProps = BaseSignInButtonProps & {
31+
/**
32+
* Additional parameters to pass to the `authorize` request.
33+
*/
34+
signInOptions?: Record<string, any>;
35+
}
3136

3237
/**
3338
* SignInButton component that uses server actions for authentication in Next.js.
@@ -55,7 +60,7 @@ export type SignInButtonProps = BaseSignInButtonProps;
5560
*/
5661
const SignInButton = forwardRef<HTMLButtonElement, SignInButtonProps>(
5762
(
58-
{className, style, children, preferences, onClick, ...rest}: SignInButtonProps,
63+
{className, style, children, preferences, onClick, signInOptions = {}, ...rest}: SignInButtonProps,
5964
ref: Ref<HTMLButtonElement>,
6065
): ReactElement => {
6166
const {signIn, signInUrl} = useAsgardeo();
@@ -72,7 +77,7 @@ const SignInButton = forwardRef<HTMLButtonElement, SignInButtonProps>(
7277
if (signInUrl) {
7378
router.push(signInUrl);
7479
} else {
75-
await signIn();
80+
await signIn(signInOptions);
7681
}
7782

7883
if (onClick) {

packages/node/src/AsgardeoNodeClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import {AsgardeoJavaScriptClient} from '@asgardeo/javascript';
2020
import {AsgardeoNodeConfig} from './models/config';
21-
import {SignOutOptions} from '@asgardeo/javascript/dist/models/client';
2221

2322
/**
2423
* Base class for implementing Asgardeo in Node.js based applications.

packages/react/src/components/actions/SignInButton/SignInButton.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import useTranslation from '../../../hooks/useTranslation';
2525
/**
2626
* Props interface of {@link SignInButton}
2727
*/
28-
export type SignInButtonProps = BaseSignInButtonProps;
28+
export type SignInButtonProps = BaseSignInButtonProps & {
29+
/**
30+
* Additional parameters to pass to the `authorize` request.
31+
*/
32+
signInOptions?: Record<string, any>;
33+
};
2934

3035
/**
3136
* SignInButton component that supports both render props and traditional props patterns.
@@ -70,8 +75,8 @@ export type SignInButtonProps = BaseSignInButtonProps;
7075
const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<HTMLButtonElement>> = forwardRef<
7176
HTMLButtonElement,
7277
SignInButtonProps
73-
>(({children, onClick, preferences, ...rest}: SignInButtonProps, ref: Ref<HTMLButtonElement>): ReactElement => {
74-
const {signIn, signInUrl} = useAsgardeo();
78+
>(({children, onClick, preferences, signInOptions: overriddenSignInOptions = {}, ...rest}: SignInButtonProps, ref: Ref<HTMLButtonElement>): ReactElement => {
79+
const {signIn, signInUrl, signInOptions} = useAsgardeo();
7580
const {t} = useTranslation(preferences?.i18n);
7681

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

8792
window.dispatchEvent(new PopStateEvent('popstate', {state: null}));
8893
} else {
89-
await signIn();
94+
await signIn(overriddenSignInOptions ?? signInOptions);
9095
}
9196

9297
if (onClick) {

packages/react/src/contexts/Asgardeo/AsgardeoContext.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import {Context, createContext} from 'react';
20-
import {HttpRequestConfig, HttpResponse, Organization} from '@asgardeo/browser';
20+
import {HttpRequestConfig, HttpResponse, Organization, SignInOptions} from '@asgardeo/browser';
2121
import AsgardeoReactClient from '../../AsgardeoReactClient';
2222

2323
/**
@@ -79,6 +79,16 @@ export type AsgardeoContextProps = {
7979
*/
8080
requestAll: (requestConfigs?: HttpRequestConfig[]) => Promise<HttpResponse<any>[]>;
8181
};
82+
/**
83+
* Optional additional parameters to be sent in the sign-in request.
84+
* This can include custom parameters that your authorization server supports.
85+
* These parameters will be included in the authorization request sent to the server.
86+
* If not provided, no additional parameters will be sent.
87+
*
88+
* @example
89+
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
90+
*/
91+
signInOptions?: SignInOptions;
8292
};
8393

8494
/**
@@ -104,6 +114,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
104114
request: () => null,
105115
requestAll: () => null,
106116
},
117+
signInOptions: {},
107118
});
108119

109120
AsgardeoContext.displayName = 'AsgardeoContext';

0 commit comments

Comments
 (0)