Skip to content

Commit 2c850a4

Browse files
Specify settings action
ref #3813
2 parents 7d38b2a + 5ba28cc commit 2c850a4

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

docs/specs/oidc.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
+ [acr_values](#acr_values)
1818
+ [code_challenge_method](#code_challenge_method)
1919
+ [nonce](#nonce)
20+
+ [x_settings_action](#x_settings_action)
2021
* [Token Request](#token-request)
2122
+ [grant_type](#grant_type)
2223
+ [id_token_hint](#id_token_hint-1)
@@ -62,6 +63,7 @@
6263
+ [Consent Screen](#consent-screen)
6364
+ [Authorized Apps page](#authorized-apps-page)
6465
+ [App Session Token](#app-session-token)
66+
+ [Settings Action](#settings-action)
6567
* [How to construct authentication request to achieve different scenarios](#how-to-construct-authentication-request-to-achieve-different-scenarios)
6668
+ [The user has NOT signed in yet in my mobile app. I want to authenticate any user.](#the-user-has-not-signed-in-yet-in-my-mobile-app-i-want-to-authenticate-any-user)
6769
+ [The user has NOT signed in yet in my mobile app. I want to authenticate any user. Possibly reuse any previous signed in sessions.](#the-user-has-not-signed-in-yet-in-my-mobile-app-i-want-to-authenticate-any-user-possibly-reuse-any-previous-signed-in-sessions)
@@ -219,6 +221,12 @@ Only `S256` is supported. `plain` is not supported.
219221

220222
To mitigate replay attacks, provide a `nonce` in the authentication request. Authgear will include the `nonce` Claim in the ID Token, and the client must verify that the `nonce` claim value is equal to the value of the `nonce` parameter sent in the authentication request. The `nonce` is recommended but it is optional. The `nonce` value is a case sensitive string. Reference: [Authentication Request](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.1).
221223

224+
### x_settings_action
225+
226+
When it is specified, the user will be redirected to the corresponding auth ui pages of the settings action. After completing the action, the user will be redirected back to the app through redirect URI.
227+
228+
Supported values: `change_password`.
229+
222230
## Token Request
223231

224232
### grant_type
@@ -229,11 +237,14 @@ To mitigate replay attacks, provide a `nonce` in the authentication request. Aut
229237
- `urn:authgear:params:oauth:grant-type:biometric-request`
230238
- `urn:authgear:params:oauth:grant-type:id-token`
231239
- `urn:authgear:params:oauth:grant-type:authorization_code`
240+
- `urn:authgear:params:oauth:grant-type:settings-action`
232241

233242
`urn:authgear:params:oauth:grant-type:anonymous-request` is for authenticating and issuing tokens directly for anonymous user.
234243

235244
`urn:authgear:params:oauth:grant-type:biometric-request` is for authenticating and issuing tokens directly for users with Biometric identity.
236245

246+
`urn:authgear:params:oauth:grant-type:settings-action` is issued upon completion of a settings action, such as change password.
247+
237248
### id_token_hint
238249

239250
When the grant type is `urn:authgear:params:oauth:grant-type:id-token`, the request must include `id_token_hint`.
@@ -631,6 +642,67 @@ When the app session token is consumed:
631642
instead of IdP sessions. Therefore, the lifetime of session cookie is bound
632643
to refresh token instead of IdP session.
633644

645+
### Settings Action
646+
647+
For first-party clients, user may want to perform specific account settings action (e.g. verify email) in the app.
648+
649+
Settings action will be started via authorization endpoint. Authentication is needed for performing settings action. Both IdP session or App session are accepted. If the login hint (app session token) is provided in the authorization endpoint, the app session cookie will be set when redirecting to the settings action ui. If the login hint is not provided, user will be redirected to the settings action ui directly and the IdP session will be used.
650+
651+
The redirect URI of the settings action should be registered in client settings `redirect_uris`.
652+
653+
After redirecting back to the app, An code of grant type `urn:ietf:params:oauth:grant-type:settings-action` will be returned to the app. The app can exchange the code to prove the completion of the settings action.
654+
655+
The following flow charts show how the settings actions work.
656+
657+
```mermaid
658+
flowchart LR
659+
subgraph /oauth2/authorize
660+
authz[authz endpoint]
661+
end
662+
subgraph settings[e.g. /settings/change_password]
663+
settings_action[settings action endpoints]
664+
end
665+
subgraph app[e.g. com.app://host/after-change-password]
666+
app_callback[app callback]
667+
end
668+
669+
SDK --app session token--> /oauth2/authorize
670+
/oauth2/authorize --app session token--> settings
671+
settings --settings action code--> app
672+
```
673+
674+
```mermaid
675+
flowchart LR
676+
subgraph /oauth2/token
677+
token[token endpoint]
678+
end
679+
app --settings action code--> /oauth2/token
680+
```
681+
682+
#### Authentication request of settings actions
683+
684+
```
685+
GET /oauth2/authorize?client_id=<Client ID>&prompt=none&response_type=settings_action
686+
&login_hint=https%3A%2F%2Fauthgear.com%2Flogin_hint%3Ftype%3Dapp_session_token%26app_session_token%3D<app session token>
687+
&id_token_hint=<ID token>
688+
&code_challenge=<code challenge>
689+
&code_challenge_method=S256
690+
&x_settings_action=<change_password>
691+
&redirect_uri=<redirect URI of the client app> HTTP/1.1
692+
Host: accounts.example.com
693+
694+
---
695+
HTTP/1.1 302 Found
696+
Set-Cookie: <session cookie>
697+
Location: <auth ui of specific settings action>
698+
```
699+
700+
Remarks:
701+
- `response_type=settings_action` is required to issue a code of grant type `urn:ietf:params:oauth:grant-type:settings-action`.
702+
- `x_settings_action` is a custom parameter to indicate the settings action.
703+
- `login_hint` is required to set the app session cookie.
704+
- `prompt` query parameter is ignored. The user will be redirected to the settings action ui directly.
705+
634706
## How to construct authentication request to achieve different scenarios
635707

636708
### The user has NOT signed in yet in my mobile app. I want to authenticate any user.

docs/specs/sdk.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,47 @@ await authgear.authorize({ ... });
271271
const enabled = await authgear.isBiometricEnabled();
272272
assert(enabled === false);
273273
```
274+
275+
## Perform settings action
276+
277+
Allow the user performs specific settings action from the app. e.g. change password. The action is only resolved when the user has completed the action.
278+
279+
```typescript
280+
// In mobile sdk
281+
interface ChangePasswordOptions {
282+
redirectURI: string;
283+
uiLocales?: string[];
284+
colorScheme?: ColorScheme;
285+
}
286+
287+
function changePassword(options: ChangePasswordOptions): Promise<Void>;
288+
289+
// In web sdk
290+
interface ChangePasswordOptions {
291+
redirectURI: string;
292+
uiLocales?: string[];
293+
colorScheme?: ColorScheme;
294+
}
295+
296+
function startChangingPassword(options: ChangePasswordOptions): Promise<Void>;
297+
298+
function finishChangingPassword(): Promise<Void>;
299+
```
300+
301+
### Intended usage
302+
303+
```typescript
304+
const userInfo = authgear.fetchUserInfo();
305+
306+
try {
307+
await authgear.startChangingPassword({
308+
redirectURI: "com.app://host/after-changing-password",
309+
})
310+
} catch (e) {
311+
// The user declined.
312+
return;
313+
}
314+
315+
// In the callback page
316+
await authgear.finishChangingPassword();
317+
```

0 commit comments

Comments
 (0)