TF-571 Get token from authentication sso
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:flutter_appauth/flutter_appauth.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/authentication_token_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/endpoint.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/service_path_extension.dart';
|
||||
|
||||
class OIDCHttpClient {
|
||||
|
||||
final DioClient _dioClient;
|
||||
final FlutterAppAuth _appAuth;
|
||||
|
||||
OIDCHttpClient(this._dioClient);
|
||||
OIDCHttpClient(this._dioClient, this._appAuth);
|
||||
|
||||
Future<OIDCResponse?> checkOIDCIsAvailable(OIDCRequest oidcRequest) async {
|
||||
final result = await _dioClient.get(
|
||||
@@ -33,4 +36,22 @@ class OIDCHttpClient {
|
||||
Future<OIDCConfiguration> getOIDCConfiguration(Uri baseUri) async {
|
||||
return OIDCConfiguration.initial();
|
||||
}
|
||||
|
||||
Future<TokenOIDC> getTokenOIDC(String clientId, String redirectUrl, String discoveryUrl, List<String> scopes) async {
|
||||
final tokenResponse = await _appAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
|
||||
clientId,
|
||||
redirectUrl,
|
||||
discoveryUrl: discoveryUrl,
|
||||
scopes: scopes,
|
||||
preferEphemeralSession: true));
|
||||
|
||||
log('OIDCHttpClient::getTokenOIDC(): token: ${tokenResponse?.accessToken}');
|
||||
|
||||
if (tokenResponse != null) {
|
||||
final tokenOIDC = tokenResponse.toTokenOIDC();
|
||||
return tokenOIDC.isTokenValid() ? tokenOIDC : TokenOIDC.empty();
|
||||
} else {
|
||||
return TokenOIDC.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user