Files
feeddeck/app/lib/utils/signin_with_apple.dart
Rico Berger 04314f116d [core] Fix Naming of Files (#122)
Fix the naming of some files: Instead of login we are always using the
term sign in and already renamed the `DesktopLoginManager` to
`DesktopSignInManager` in #106. During the renaming we forgot to rename
the file which is now done.

We also renamed the `sign_in_with_apple.dart` file to
`signin_with_apple.dart`, because the other files also do not contain an
underscore between sign and in.
2024-01-31 19:32:23 +01:00

34 lines
1.1 KiB
Dart

import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
/// [signInWithApple] performs Apple sign in on iOS and macOS.
/// See https://supabase.com/docs/guides/auth/social-login/auth-apple?platform=flutter#using-native-sign-in-with-apple-in-flutter
Future<AuthResponse> signInWithApple() async {
final rawNonce = Supabase.instance.client.auth.generateRawNonce();
final hashedNonce = sha256.convert(utf8.encode(rawNonce)).toString();
final credential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
nonce: hashedNonce,
);
final idToken = credential.identityToken;
if (idToken == null) {
throw const AuthException(
'Could not find ID Token from generated credential.',
);
}
return Supabase.instance.client.auth.signInWithIdToken(
provider: OAuthProvider.apple,
idToken: idToken,
nonce: rawNonce,
);
}