Sign in with Apple

This commit is contained in:
Hillel Coren 2022-07-10 13:41:02 +03:00
parent 7d2e4ef86d
commit 86d7af0e71
2 changed files with 102 additions and 43 deletions

View File

@ -10,6 +10,7 @@ import 'package:invoiceninja_flutter/ui/app/app_title_bar.dart';
// Package imports: // Package imports:
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:rounded_loading_button/rounded_loading_button.dart'; import 'package:rounded_loading_button/rounded_loading_button.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
// Project imports: // Project imports:
@ -576,50 +577,107 @@ class _LoginState extends State<LoginView> {
Padding( Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: 20, bottom: 10, left: 16, right: 16), top: 20, bottom: 10, left: 16, right: 16),
child: RoundedLoadingButton( child: _loginType == LOGIN_TYPE_APPLE
height: 50, ? SignInWithAppleButton(
borderRadius: 4, onPressed: () async {
width: 430, final credential =
controller: _buttonController, await SignInWithApple.getAppleIDCredential(
color: state.accentColor, scopes: [
onPressed: () => _submitForm(), AppleIDAuthorizationScopes.email,
child: Row( AppleIDAuthorizationScopes.fullName,
mainAxisSize: MainAxisSize.min, ],
children: [ webAuthenticationOptions:
if (_loginType == LOGIN_TYPE_EMAIL) WebAuthenticationOptions(
Icon(Icons.mail, color: Colors.white) clientId: 'com.invoiceninja.client',
else if (_loginType == LOGIN_TYPE_MICROSOFT) redirectUri: kIsWeb
Icon(MdiIcons.microsoft, color: Colors.white) ? Uri.parse(
else if (_loginType == LOGIN_TYPE_APPLE) 'https://staging.invoicing.co/')
Icon(MdiIcons.apple, color: Colors.white) : Uri.parse(
else 'https://invoicing.co/auth/apple'),
ClipOval( ),
child: Image.asset( );
'assets/images/google_logo.png',
width: 30, // ignore: avoid_print
height: 30), print('## credentials: $credential');
),
SizedBox(width: 10), /*
Text( // This is the endpoint that will convert an authorization code obtained
_recoverPassword // via Sign in with Apple into a session in your system
? localization.recoverPassword final signInWithAppleEndpoint = Uri(
: _createAccount scheme: 'https',
? (_loginType == LOGIN_TYPE_EMAIL host:
? localization.emailSignUp 'flutter-sign-in-with-apple-example.glitch.me',
: _loginType == LOGIN_TYPE_MICROSOFT path: '/sign_in_with_apple',
? localization.microsoftSignUp queryParameters: <String, String>{
: localization.googleSignUp) 'code': credential.authorizationCode,
: (_loginType == LOGIN_TYPE_EMAIL if (credential.givenName != null)
? localization.emailSignIn 'firstName': credential.givenName,
: _loginType == LOGIN_TYPE_MICROSOFT if (credential.familyName != null)
? localization.microsoftSignIn 'lastName': credential.familyName,
: localization.googleSignIn), },
style: );
TextStyle(fontSize: 18, color: Colors.white),
final session = await http.Client().post(
signInWithAppleEndpoint,
);
// If we got this far, a session based on the Apple ID credential has been created in your system,
// and you can now set this as the app's session
// ignore: avoid_print
print(session);
*/
},
) )
], : RoundedLoadingButton(
), height: 50,
), borderRadius: 4,
width: 430,
controller: _buttonController,
color: state.accentColor,
onPressed: () => _submitForm(),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (_loginType == LOGIN_TYPE_EMAIL)
Icon(Icons.mail, color: Colors.white)
else if (_loginType == LOGIN_TYPE_MICROSOFT)
Icon(MdiIcons.microsoft,
color: Colors.white)
else if (_loginType == LOGIN_TYPE_APPLE)
Icon(MdiIcons.apple, color: Colors.white)
else
ClipOval(
child: Image.asset(
'assets/images/google_logo.png',
width: 30,
height: 30),
),
SizedBox(width: 10),
Text(
_recoverPassword
? localization.recoverPassword
: _createAccount
? (_loginType == LOGIN_TYPE_EMAIL
? localization.emailSignUp
: _loginType ==
LOGIN_TYPE_MICROSOFT
? localization
.microsoftSignUp
: localization.googleSignUp)
: (_loginType == LOGIN_TYPE_EMAIL
? localization.emailSignIn
: _loginType ==
LOGIN_TYPE_MICROSOFT
? localization
.microsoftSignIn
: localization
.googleSignIn),
style: TextStyle(
fontSize: 18, color: Colors.white),
)
],
),
),
), ),
if (!_isSelfHosted && if (!_isSelfHosted &&
!_recoverPassword && !_recoverPassword &&

View File

@ -5,6 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js"></script>
<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
<script type="text/javascript"> <script type="text/javascript">
pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js"; pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js";
</script> </script>