signInWithProvider method

Future<AuthResponse> signInWithProvider({
  1. required OAuthProvider provider,
  2. String? connection,
  3. String? authorizationCode,
  4. String? idToken,
  5. String? redirectUri,
  6. String? nonce,
  7. String? codeVerifier,
})

Exchange a provider authorization code or OIDC ID token for a Mortar session. The app must validate OAuth state before this call.

Implementation

Future<AuthResponse> signInWithProvider({
  required OAuthProvider provider,
  String? connection,
  String? authorizationCode,
  String? idToken,
  String? redirectUri,
  String? nonce,
  String? codeVerifier,
}) async {
  final res = await request(
    _opts,
    method: 'POST',
    path: '/v1/auth/oauth/${provider.wireName}',
    json: {
      if (connection != null) 'connection': connection,
      if (authorizationCode != null) 'authorization_code': authorizationCode,
      if (idToken != null) 'id_token': idToken,
      if (redirectUri != null) 'redirect_uri': redirectUri,
      if (nonce != null) 'nonce': nonce,
      if (codeVerifier != null) 'code_verifier': codeVerifier,
    },
  ) as Map<String, dynamic>;
  final response = AuthResponse.fromJson(res);
  _setSession(_sessionFromAuth(response), AuthChangeEvent.signedIn);
  return response;
}