Skip to content

Commit

Permalink
feat: add the Logout function to the Authenticate button.
Browse files Browse the repository at this point in the history
  • Loading branch information
cwp0 committed Jul 20, 2023
1 parent d6f6c58 commit abc0f71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ class _MyAppState extends State<MyApp> {
final result = await _casdoor.show();
// Get code
final code = Uri.parse(result).queryParameters['code'] ?? "";
final response = await _casdoor.requestOauthAccessToken(code);
setState(() {
_token = jsonDecode(response.body)["access_token"] as String;
});
if(_token == 'User is not logged in') {
final response = await _casdoor.requestOauthAccessToken(code);
setState(() {
_token = jsonDecode(response.body)["access_token"] as String;
});
} else {
await _casdoor.tokenLogout('idTokenHint', 'postLogoutRedirectUri', 'state');
setState(() {
_token = 'User is not logged in';
});
}
}

@override
Expand All @@ -81,7 +88,7 @@ class _MyAppState extends State<MyApp> {
),
floatingActionButton: FloatingActionButton(
onPressed: authenticate,
tooltip: 'Authenticate',
tooltip: _token == 'User is not logged in' ? 'Authenticate' : 'Logout',
child: const Icon(Icons.people),
)),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/casdoor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Casdoor {
scheme: parseScheme(),
host: parseHost(),
port: parsePort(),
path: "api/login/oauth/logout",
path: "api/logout",
),
body: {
'id_token_hint ': idTokenHint,
Expand Down

0 comments on commit abc0f71

Please sign in to comment.