Skip to content

Commit b2505c1

Browse files
Support add login ID setting action
ref DEV-2411
2 parents f077ac1 + 991a054 commit b2505c1

File tree

3 files changed

+135
-20
lines changed

3 files changed

+135
-20
lines changed

example/lib/main.dart

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,36 @@ class _MyAppState extends State<MyApp> {
593593
_onPressChangePassword(context);
594594
},
595595
),
596+
SessionStateButton(
597+
sessionState: _authgear.sessionState,
598+
targetState: SessionState.authenticated,
599+
label: "Add Email",
600+
onPressed: _unconfigured || _loading
601+
? null
602+
: () {
603+
_onPressAddEmail(context);
604+
},
605+
),
606+
SessionStateButton(
607+
sessionState: _authgear.sessionState,
608+
targetState: SessionState.authenticated,
609+
label: "Add Phone",
610+
onPressed: _unconfigured || _loading
611+
? null
612+
: () {
613+
_onPressAddPhone(context);
614+
},
615+
),
616+
SessionStateButton(
617+
sessionState: _authgear.sessionState,
618+
targetState: SessionState.authenticated,
619+
label: "Add Username",
620+
onPressed: _unconfigured || _loading
621+
? null
622+
: () {
623+
_onPressAddUsername(context);
624+
},
625+
),
596626
SessionStateButton(
597627
sessionState: _authgear.sessionState,
598628
targetState: SessionState.authenticated,
@@ -907,7 +937,6 @@ class _MyAppState extends State<MyApp> {
907937
await _authgear.changePassword(
908938
redirectURI: redirectURI,
909939
colorScheme: _getColorScheme(context),
910-
wechatRedirectURI: wechatRedirectURI,
911940
);
912941
} catch (e) {
913942
onError(context, e);
@@ -926,7 +955,60 @@ class _MyAppState extends State<MyApp> {
926955
await _authgear.deleteAccount(
927956
redirectURI: redirectURI,
928957
colorScheme: _getColorScheme(context),
929-
wechatRedirectURI: wechatRedirectURI,
958+
);
959+
} catch (e) {
960+
onError(context, e);
961+
} finally {
962+
setState(() {
963+
_loading = false;
964+
});
965+
}
966+
}
967+
968+
Future<void> _onPressAddEmail(BuildContext context) async {
969+
try {
970+
setState(() {
971+
_loading = true;
972+
});
973+
await _authgear.addEmail(
974+
redirectURI: redirectURI,
975+
colorScheme: _getColorScheme(context),
976+
);
977+
} catch (e) {
978+
onError(context, e);
979+
} finally {
980+
setState(() {
981+
_loading = false;
982+
});
983+
}
984+
}
985+
986+
Future<void> _onPressAddPhone(BuildContext context) async {
987+
try {
988+
setState(() {
989+
_loading = true;
990+
});
991+
await _authgear.addPhone(
992+
redirectURI: redirectURI,
993+
colorScheme: _getColorScheme(context),
994+
);
995+
} catch (e) {
996+
onError(context, e);
997+
} finally {
998+
setState(() {
999+
_loading = false;
1000+
});
1001+
}
1002+
}
1003+
1004+
Future<void> _onPressAddUsername(BuildContext context) async {
1005+
try {
1006+
setState(() {
1007+
_loading = true;
1008+
});
1009+
await _authgear.addUsername(
1010+
redirectURI: redirectURI,
1011+
colorScheme: _getColorScheme(context),
9301012
);
9311013
} catch (e) {
9321014
onError(context, e);

lib/src/container.dart

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,12 @@ class SettingsActionOptions {
166166
final String redirectURI;
167167
final List<String>? uiLocales;
168168
final ColorScheme? colorScheme;
169-
final String? wechatRedirectURI;
170169

171170
SettingsActionOptions({
172171
required this.settingAction,
173172
required this.redirectURI,
174173
this.uiLocales,
175174
this.colorScheme,
176-
this.wechatRedirectURI,
177175
});
178176

179177
OIDCAuthenticationRequest toRequest(String clientID, String idTokenHint,
@@ -196,7 +194,6 @@ class SettingsActionOptions {
196194
colorScheme: colorScheme,
197195
idTokenHint: idTokenHint,
198196
loginHint: loginHint,
199-
wechatRedirectURI: wechatRedirectURI,
200197
settingsAction: settingAction,
201198
);
202199
}
@@ -562,7 +559,6 @@ class Authgear implements AuthgearHttpClientDelegate {
562559
required String redirectURI,
563560
List<String>? uiLocales,
564561
ColorScheme? colorScheme,
565-
String? wechatRedirectURI,
566562
}) async {
567563
final idTokenHint = this.idTokenHint;
568564
final refreshToken = _refreshToken;
@@ -582,18 +578,11 @@ class Authgear implements AuthgearHttpClientDelegate {
582578
redirectURI: redirectURI,
583579
uiLocales: uiLocales,
584580
colorScheme: colorScheme,
585-
wechatRedirectURI: wechatRedirectURI,
586581
);
587582

588583
final request = await internalCreateSettingsActionRequest(
589584
clientID, idTokenHint, loginHint, options);
590585

591-
if (wechatRedirectURI != null) {
592-
await native.registerWechatRedirectURI(
593-
onWechatRedirectURI: _onWechatRedirectURI,
594-
wechatRedirectURI: wechatRedirectURI);
595-
}
596-
597586
final resultURL = await _uiImplementation.openAuthorizationURL(
598587
url: request.url.toString(),
599588
redirectURI: redirectURI,
@@ -608,32 +597,64 @@ class Authgear implements AuthgearHttpClientDelegate {
608597
Future<void> changePassword(
609598
{required String redirectURI,
610599
List<String>? uiLocales,
611-
ColorScheme? colorScheme,
612-
String? wechatRedirectURI}) {
600+
ColorScheme? colorScheme}) {
613601
return _openSettingsAction(
614602
action: SettingsAction.changePassword,
615603
redirectURI: redirectURI,
616604
uiLocales: uiLocales,
617605
colorScheme: colorScheme,
618-
wechatRedirectURI: wechatRedirectURI,
619606
);
620607
}
621608

622609
Future<void> deleteAccount(
623610
{required String redirectURI,
624611
List<String>? uiLocales,
625-
ColorScheme? colorScheme,
626-
String? wechatRedirectURI}) async {
612+
ColorScheme? colorScheme}) async {
627613
await _openSettingsAction(
628614
action: SettingsAction.deleteAccount,
629615
redirectURI: redirectURI,
630616
uiLocales: uiLocales,
631617
colorScheme: colorScheme,
632-
wechatRedirectURI: wechatRedirectURI,
633618
);
634619
await _clearSession(SessionStateChangeReason.invalid);
635620
}
636621

622+
Future<void> addEmail(
623+
{required String redirectURI,
624+
List<String>? uiLocales,
625+
ColorScheme? colorScheme}) async {
626+
await _openSettingsAction(
627+
action: SettingsAction.addEmail,
628+
redirectURI: redirectURI,
629+
uiLocales: uiLocales,
630+
colorScheme: colorScheme,
631+
);
632+
}
633+
634+
Future<void> addPhone(
635+
{required String redirectURI,
636+
List<String>? uiLocales,
637+
ColorScheme? colorScheme}) async {
638+
await _openSettingsAction(
639+
action: SettingsAction.addPhone,
640+
redirectURI: redirectURI,
641+
uiLocales: uiLocales,
642+
colorScheme: colorScheme,
643+
);
644+
}
645+
646+
Future<void> addUsername(
647+
{required String redirectURI,
648+
List<String>? uiLocales,
649+
ColorScheme? colorScheme}) async {
650+
await _openSettingsAction(
651+
action: SettingsAction.addUsername,
652+
redirectURI: redirectURI,
653+
uiLocales: uiLocales,
654+
colorScheme: colorScheme,
655+
);
656+
}
657+
637658
Future<void> refreshIDToken() async {
638659
if (shouldRefreshAccessToken) {
639660
await refreshAccessToken();

lib/src/type.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ extension ActorTokenTypeExtension on ActorTokenType {
158158
}
159159
}
160160

161-
enum SettingsAction { changePassword, deleteAccount }
161+
enum SettingsAction {
162+
changePassword,
163+
deleteAccount,
164+
addEmail,
165+
addPhone,
166+
addUsername,
167+
}
162168

163169
extension SettingsActionExtension on SettingsAction {
164170
String get value {
@@ -167,6 +173,12 @@ extension SettingsActionExtension on SettingsAction {
167173
return "change_password";
168174
case SettingsAction.deleteAccount:
169175
return "delete_account";
176+
case SettingsAction.addEmail:
177+
return "add_email";
178+
case SettingsAction.addPhone:
179+
return "add_phone";
180+
case SettingsAction.addUsername:
181+
return "add_username";
170182
}
171183
}
172184
}

0 commit comments

Comments
 (0)