Skip to content

Commit 1a841e3

Browse files
committed
feat(auth): add acrValues for mfa
1 parent 3ea729d commit 1a841e3

File tree

3 files changed

+56
-30
lines changed

3 files changed

+56
-30
lines changed

packages/auth/README.md

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
- [UserInfo](#UserInfo)
77
- [UserSession](#UserSession)
88

9-
## Variables
10-
11-
### UserContext
12-
13-
**UserContext**: `Context`<[`UserContext`](#usercontext)\>
14-
159
## Functions
1610

1711
### UserContextProvider
@@ -50,7 +44,7 @@ ___
5044

5145
### useUser
5246

53-
**useUser**(): [`UserContext`](#usercontext)
47+
**useUser**(): `UserContext`
5448

5549
Returns the user context previously established with `UserContextProvider`.
5650

@@ -65,7 +59,7 @@ useEffect(() => {
6559

6660
#### Returns
6761

68-
[`UserContext`](#usercontext)
62+
`UserContext`
6963

7064

7165
## UserContext
@@ -94,55 +88,79 @@ Provides the `UserInfo` object if the user is authenticated.
9488

9589
___
9690

97-
### loginUrl
98-
99-
`Optional` **loginUrl**: `string`
100-
101-
Set to the URL that the user is redirected to initiate the authorization flow. Useful when you need to start the login flow in a separate window or tab. Use in combination with `login({ refresh: false })`.
102-
103-
___
104-
105-
### session
106-
107-
`Optional` **session**: [`UserSession`](#UserSession)
108-
109-
Provides the `UserSession` object if the user is authenticated.
91+
### login
11092

111-
## Methods
93+
`Optional` **login**: (`opts?`: [`LoginOptions`](#LoginOptions)) => `void`
11294

113-
### login
95+
#### Type declaration
11496

115-
`Optional` **login**(`opts?`): `void`
97+
▸ (`opts?`): `void`
11698

11799
Function to initiate the login flow.
118100

119-
#### Parameters
101+
##### Parameters
120102

121103
| Name | Type |
122104
| :------ | :------ |
123105
| `opts?` | [`LoginOptions`](#LoginOptions) |
124106

125-
#### Returns
107+
##### Returns
126108

127109
`void`
128110

129111
___
130112

113+
### loginUrl
114+
115+
`Optional` **loginUrl**: `string`
116+
117+
Set to the URL that the user is redirected to initiate the authorization flow. Useful when you need to start the login flow in a separate window or tab. Use in combination with `login({ refresh: false })`.
118+
119+
___
120+
131121
### logout
132122

133-
`Optional` **logout**(): `void`
123+
`Optional` **logout**: () => `void`
124+
125+
#### Type declaration
126+
127+
▸ (): `void`
134128

135129
Function to log the user out.
136130

137-
#### Returns
131+
##### Returns
138132

139133
`void`
140134

135+
___
136+
137+
### session
138+
139+
`Optional` **session**: [`UserSession`](#UserSession)
140+
141+
Provides the `UserSession` object if the user is authenticated.
142+
141143

142144
## ProviderOptions
143145

144146
## Properties
145147

148+
### acrValues
149+
150+
`Optional` **acrValues**: `string`
151+
152+
Request a type of multi-factor authentication. Currently, `mfa` is the only supported value.
153+
154+
___
155+
156+
### additionalParameters
157+
158+
`Optional` **additionalParameters**: `string`
159+
160+
Additional query parameters, such as `state=xyz`.
161+
162+
___
163+
146164
### autoLogin
147165

148166
`Optional` **autoLogin**: `boolean`

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@emdgroup/react-auth",
3-
"version": "1.5.3",
3+
"version": "1.6.0",
44
"description": "React hooks implementing the Authorization Code Grant Flow with PKCE.",
55
"type": "module",
66
"main": "./dist/index.js",

packages/auth/src/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ export interface ProviderOptions {
166166
refreshSession?: boolean;
167167
/** Whether the authorization server prompts the user for re-authentication. */
168168
prompt?: 'login';
169+
/** Request a type of multi-factor authentication. Currently, `mfa` is the only supported value. */
170+
acrValues?: string;
171+
/** Additional query parameters, such as `state=xyz`. */
172+
additionalParameters?: string;
169173
}
170174

171175
/**
@@ -198,6 +202,8 @@ export function UserContextProvider({
198202
redirectUri,
199203
refreshSession: refreshSessionOpt = false,
200204
prompt,
205+
acrValues,
206+
additionalParameters,
201207
}: ProviderOptions): JSX.Element {
202208
const [session, updateSession, clearSession] = useLocalStorage('session', isSession);
203209

@@ -232,12 +238,14 @@ export function UserContextProvider({
232238
code_challenge_method: 'S256',
233239
code_challenge: challenge,
234240
prompt,
241+
acr_values: acrValues,
242+
...(additionalParameters ? querystring.parse(additionalParameters) : undefined),
235243
});
236244

237245
setLoginUrl(url);
238246

239247
if (redirect) document.location.href = url;
240-
}, [setKey, idpHost, clientId, domainHint, redirectUri, setEntrypoint, prompt]);
248+
}, [setKey, idpHost, clientId, domainHint, redirectUri, setEntrypoint, prompt, acrValues, additionalParameters]);
241249

242250
const logout = useCallback((): void => {
243251
clearSession();

0 commit comments

Comments
 (0)