Skip to content

Commit 0593829

Browse files
authored
Support linkOAuth settings action #5731
ref DEV-3595
2 parents ea93413 + 63f68e3 commit 0593829

49 files changed

Lines changed: 1707 additions & 74 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.make-lint-translation-keys-expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ resources/authgear/templates/en/web/authflowv2/layout.html:5:14: template transl
2929
resources/authgear/templates/en/web/authflowv2/login.html:256:37: translation key not defined: "%s-icon"
3030
resources/authgear/templates/en/web/authflowv2/preview_widget.html:127:39: translation key not defined: "%s-icon"
3131
resources/authgear/templates/en/web/authflowv2/settings_identity_list_email.html:58:44: translation key not defined: "v2.page.settings-identity-list-email.default.provider.%s"
32-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:57:32: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
33-
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:106:35: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
32+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:77:32: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
33+
resources/authgear/templates/en/web/authflowv2/settings_identity_list_oauth.html:128:35: translation key not defined: "v2.page.settings-identity-oauth.default.provider.%s"
3434
resources/authgear/templates/en/web/authflowv2/settings_identity_list_phone.html:58:44: translation key not defined: "v2.page.settings-identity-list-phone.default.provider.%s"
3535
resources/authgear/templates/en/web/authflowv2/settings_layout.html:3:14: template translation is forbidden: `widget`
3636
resources/authgear/templates/en/web/authflowv2/settings_mfa.html:69:44: translation key not defined: "/settings/mfa/create_oob_otp_%s"

.vettedpositions

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
/pkg/auth/handler/webapp/app_static_assets.go:39:33: requestcontext
5959
/pkg/auth/handler/webapp/auth_entry_point_middleware.go:35:10: requestcontext
6060
/pkg/auth/handler/webapp/authflow_change_password.go:96:26: requestcontext
61-
/pkg/auth/handler/webapp/authflow_controller.go:1062:30: requestcontext
62-
/pkg/auth/handler/webapp/authflow_controller.go:1067:24: requestcontext
63-
/pkg/auth/handler/webapp/authflow_controller.go:1075:19: requestcontext
64-
/pkg/auth/handler/webapp/authflow_controller.go:1083:18: requestcontext
61+
/pkg/auth/handler/webapp/authflow_controller.go:1070:30: requestcontext
62+
/pkg/auth/handler/webapp/authflow_controller.go:1075:24: requestcontext
63+
/pkg/auth/handler/webapp/authflow_controller.go:1083:19: requestcontext
64+
/pkg/auth/handler/webapp/authflow_controller.go:1091:18: requestcontext
6565
/pkg/auth/handler/webapp/authflow_create_password.go:132:26: requestcontext
6666
/pkg/auth/handler/webapp/authflow_enter_oob_otp.go:156:26: requestcontext
6767
/pkg/auth/handler/webapp/authflow_enter_password.go:139:26: requestcontext
@@ -128,7 +128,7 @@
128128
/pkg/auth/handler/webapp/authflowv2/settings_identity_edit_phone.go:134:30: requestcontext
129129
/pkg/auth/handler/webapp/authflowv2/settings_identity_edit_username.go:121:30: requestcontext
130130
/pkg/auth/handler/webapp/authflowv2/settings_identity_list_email.go:153:30: requestcontext
131-
/pkg/auth/handler/webapp/authflowv2/settings_identity_list_oauth.go:148:30: requestcontext
131+
/pkg/auth/handler/webapp/authflowv2/settings_identity_list_oauth.go:242:30: requestcontext
132132
/pkg/auth/handler/webapp/authflowv2/settings_identity_list_phone.go:158:30: requestcontext
133133
/pkg/auth/handler/webapp/authflowv2/settings_identity_list_username.go:87:30: requestcontext
134134
/pkg/auth/handler/webapp/authflowv2/settings_identity_new_username.go:74:30: requestcontext
@@ -239,11 +239,11 @@
239239
/pkg/auth/handler/webapp/setup_whatsapp_otp.go:62:27: requestcontext
240240
/pkg/auth/handler/webapp/signup.go:90:27: requestcontext
241241
/pkg/auth/handler/webapp/signup.go:101:28: requestcontext
242-
/pkg/auth/handler/webapp/sso_callback.go:41:53: requestcontext
243-
/pkg/auth/handler/webapp/sso_callback.go:47:26: requestcontext
244-
/pkg/auth/handler/webapp/sso_callback.go:55:58: requestcontext
245-
/pkg/auth/handler/webapp/sso_callback.go:60:44: requestcontext
246-
/pkg/auth/handler/webapp/sso_callback.go:71:44: requestcontext
242+
/pkg/auth/handler/webapp/sso_callback.go:42:53: requestcontext
243+
/pkg/auth/handler/webapp/sso_callback.go:48:26: requestcontext
244+
/pkg/auth/handler/webapp/sso_callback.go:65:58: requestcontext
245+
/pkg/auth/handler/webapp/sso_callback.go:77:44: requestcontext
246+
/pkg/auth/handler/webapp/sso_callback.go:92:44: requestcontext
247247
/pkg/auth/handler/webapp/tester.go:279:27: requestcontext
248248
/pkg/auth/handler/webapp/turbo_response_writer.go:29:25: requestcontext
249249
/pkg/auth/handler/webapp/turbo_response_writer.go:34:29: requestcontext
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Settings Action: Connect OAuth — JS Web SDK Implementation Plan
2+
3+
> Source repo: `authgear-sdk-js`. Companion plan: `connect-oauth-server.md`.
4+
> Platform: **authgear-web**.
5+
6+
## Goal
7+
8+
Expose `startLinkOAuth(options)` / `finishLinkOAuth()` on the public `WebContainer`, mirroring the pattern of every other settings-action pair (e.g. `startAddEmail` / `finishAddEmail`).
9+
10+
## Public API (target)
11+
12+
`oauthProviderAlias` is **required**. The server rejects requests without it.
13+
14+
```ts
15+
// Start — redirects the browser to Authgear, which redirects to the OAuth provider
16+
await authgear.startLinkOAuth({
17+
redirectURI: "https://myapp.com/oauth-callback",
18+
oauthProviderAlias: "google", // required
19+
});
20+
21+
// Finish — called on the redirectURI page after the round-trip
22+
await authgear.finishLinkOAuth();
23+
```
24+
25+
---
26+
27+
## File-by-file changes
28+
29+
### 1. `packages/authgear-core/src/types.ts`
30+
31+
**1a. Extend the `SettingsAction` enum.** Add a new member after `ChangeUsername` (the current last entry):
32+
33+
```ts
34+
/**
35+
* Connect an OAuth provider in Authgear settings page.
36+
*/
37+
LinkOAuth = "link_oauth",
38+
```
39+
40+
**1b. Extend the `xSettingsAction` union in `_OIDCAuthenticationRequest`.** Append `"link_oauth"`:
41+
42+
```ts
43+
xSettingsAction?:
44+
| "change_password"
45+
| "delete_account"
46+
| "add_email"
47+
| "add_phone"
48+
| "add_username"
49+
| "change_email"
50+
| "change_phone"
51+
| "change_username"
52+
| "link_oauth";
53+
```
54+
55+
`oauthProviderAlias?: string` is **already** on `_OIDCAuthenticationRequest` — no new field needed. `startSettingsAction` spreads `...options` into `authorizeEndpoint`, so adding `oauthProviderAlias` to `_InternalSettingsActionOptions` (step 2) is sufficient to forward it.
56+
57+
---
58+
59+
### 2. `packages/authgear-web/src/types.ts`
60+
61+
**2a. Add `LinkOAuthOptions`.** Place after `ChangeUsernameOptions`:
62+
63+
```ts
64+
/**
65+
* Options for connecting an OAuth provider via settings action.
66+
* @public
67+
*/
68+
export interface LinkOAuthOptions extends SettingsActionOptions {
69+
/**
70+
* The alias of the OAuth provider to link,
71+
* as configured in Authgear Portal under Social / Enterprise Login.
72+
* This field is required.
73+
*/
74+
oauthProviderAlias: string;
75+
}
76+
```
77+
78+
**2b. Add `oauthProviderAlias?` to `_InternalSettingsActionOptions`:**
79+
80+
```ts
81+
export interface _InternalSettingsActionOptions extends SettingsActionOptions {
82+
qLoginID?: string;
83+
oauthProviderAlias?: string;
84+
}
85+
```
86+
87+
---
88+
89+
### 3. `packages/authgear-web/src/container.ts`
90+
91+
No change to `startSettingsAction` — it already spreads `...options` into `authorizeEndpoint`, so `oauthProviderAlias` flows through automatically once it is on `_InternalSettingsActionOptions`.
92+
93+
**3a. Add `startLinkOAuth`.** Place after `startChangeUsername`:
94+
95+
```ts
96+
/**
97+
* Start settings action "link_oauth" by redirecting to the authorization endpoint.
98+
* @public
99+
*/
100+
async startLinkOAuth(options: LinkOAuthOptions): Promise<void> {
101+
await this.startSettingsAction(SettingsAction.LinkOAuth, options);
102+
}
103+
```
104+
105+
**3b. Add `finishLinkOAuth`.** Place after `finishChangeUsername`:
106+
107+
```ts
108+
/**
109+
* Finish settings action "link_oauth".
110+
* @public
111+
*/
112+
async finishLinkOAuth(): Promise<void> {
113+
return this.finishSettingsAction();
114+
}
115+
```
116+
117+
`finishSettingsAction` delegates to `this.baseContainer._finishSettingsAction(window.location.href)`, identical to all other finish methods except `finishDeleteAccount`.
118+
119+
---
120+
121+
### 4. Public exports
122+
123+
Add `LinkOAuthOptions` to `packages/authgear-web/src/index.ts` if types are explicitly re-exported there. `WebContainer` is already re-exported so the new methods come along automatically.
124+
125+
---
126+
127+
## Verification
128+
129+
- **Type-check:** `npx tsc --noEmit` in `packages/authgear-core` and `packages/authgear-web`.
130+
- **Build:** `npm run build` in `packages/authgear-web`.
131+
- **API Extractor:** new `startLinkOAuth`, `finishLinkOAuth`, and `LinkOAuthOptions` should appear in the public API report.
132+
- **Manual:** complete the round trip against a local `authgear-server` with the server-side changes applied.
133+
134+
---
135+
136+
## Checklist
137+
138+
- [ ] `SettingsAction.LinkOAuth` in `authgear-core/src/types.ts`
139+
- [ ] `"link_oauth"` in the `xSettingsAction` union
140+
- [ ] `LinkOAuthOptions` in `authgear-web/src/types.ts`
141+
- [ ] `oauthProviderAlias?` on `_InternalSettingsActionOptions`
142+
- [ ] `startLinkOAuth` / `finishLinkOAuth` on `WebContainer`
143+
- [ ] `LinkOAuthOptions` exported from the package entry point
144+
- [ ] TypeScript build / typecheck pass
145+
- [ ] API Extractor report regenerated and reviewed

0 commit comments

Comments
 (0)