Microsoft Login
This commit is contained in:
parent
e228366a23
commit
db4433b5e6
|
|
@ -94,6 +94,9 @@ const String kProductPlanEnterprise5 = 'v1_enterprise_5_yearly';
|
|||
const String kProductPlanEnterprise10 = 'v1_enterprise_10_yearly';
|
||||
const String kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
||||
|
||||
const String kOAuthProviderMicrosoft = 'microsoft';
|
||||
const String kOAuthProviderGoogle = 'google';
|
||||
|
||||
const kProductPlans = [
|
||||
kProductPlanPro,
|
||||
kProductPlanEnterprise2,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class AuthRepository {
|
|||
@required String idToken,
|
||||
@required String accessToken,
|
||||
@required String referralCode,
|
||||
@required String provider,
|
||||
}) async {
|
||||
final credentials = {
|
||||
'terms_of_service': true,
|
||||
|
|
@ -61,7 +62,7 @@ class AuthRepository {
|
|||
'token_name': _tokenName,
|
||||
'id_token': idToken,
|
||||
//'access_token': accessToken,
|
||||
'provider': 'google',
|
||||
'provider': provider,
|
||||
'platform': getPlatformName(),
|
||||
};
|
||||
|
||||
|
|
@ -102,10 +103,11 @@ class AuthRepository {
|
|||
@required String accessToken,
|
||||
@required String url,
|
||||
@required String secret,
|
||||
@required String platform}) async {
|
||||
@required String platform,
|
||||
@required String provider}) async {
|
||||
final credentials = {
|
||||
'id_token': idToken,
|
||||
'provider': 'google',
|
||||
'provider': provider,
|
||||
};
|
||||
url = formatApiUrl(url) + '/oauth_login';
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class OAuthLoginRequest implements StartLoading {
|
|||
@required this.url,
|
||||
@required this.secret,
|
||||
@required this.platform,
|
||||
@required this.provider,
|
||||
@required this.oneTimePassword,
|
||||
});
|
||||
|
||||
|
|
@ -39,6 +40,7 @@ class OAuthLoginRequest implements StartLoading {
|
|||
final String url;
|
||||
final String secret;
|
||||
final String platform;
|
||||
final String provider;
|
||||
final String oneTimePassword;
|
||||
}
|
||||
|
||||
|
|
@ -130,11 +132,13 @@ class OAuthSignUpRequest implements StartLoading {
|
|||
@required this.completer,
|
||||
@required this.idToken,
|
||||
@required this.accessToken,
|
||||
@required this.provider,
|
||||
});
|
||||
|
||||
final Completer completer;
|
||||
final String idToken;
|
||||
final String accessToken;
|
||||
final String provider;
|
||||
}
|
||||
|
||||
class UserVerifiedPassword {}
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ Middleware<AppState> _createOAuthLoginRequest(AuthRepository repository) {
|
|||
accessToken: action.accessToken,
|
||||
url: action.url,
|
||||
secret: action.secret,
|
||||
provider: action.provider,
|
||||
platform: action.platform)
|
||||
.then((data) {
|
||||
_saveAuthLocal(action.url);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@
|
|||
import 'dart:async';
|
||||
|
||||
// Flutter imports:
|
||||
import 'package:aad_oauth/model/config.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/main_app.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:aad_oauth/aad_oauth.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
|
|
@ -106,6 +110,17 @@ class LoginVM {
|
|||
final Function(BuildContext, Completer<Null> completer)
|
||||
onMicrosoftSignUpPressed;
|
||||
|
||||
static final Config config = Config(
|
||||
tenant: '3196aaac-9636-4f91-8f04-3297e2654909',
|
||||
clientId: '1023b9ce-5b09-4f04-98f8-e1ed85a72332',
|
||||
scope: 'openid profile offline_access',
|
||||
redirectUri: kIsWeb
|
||||
? 'http://localhost:8483'
|
||||
: 'https://login.live.com/oauth20_desktop.srf',
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
static final AadOAuth oauth = AadOAuth(config);
|
||||
|
||||
static LoginVM fromStore(Store<AppState> store) {
|
||||
void _handleLogin({BuildContext context, bool isSignUp = false}) {
|
||||
final layout = calculateLayout(context);
|
||||
|
|
@ -168,6 +183,7 @@ class LoginVM {
|
|||
url: _formatApiUrl(url),
|
||||
secret: secret.trim(),
|
||||
platform: getPlatform(context),
|
||||
provider: kOAuthProviderGoogle,
|
||||
oneTimePassword: oneTimePassword,
|
||||
));
|
||||
completer.future.then((_) => _handleLogin(context: context));
|
||||
|
|
@ -196,6 +212,7 @@ class LoginVM {
|
|||
completer: completer,
|
||||
idToken: idToken,
|
||||
accessToken: accessToken,
|
||||
provider: kOAuthProviderGoogle,
|
||||
));
|
||||
completer.future
|
||||
.then((_) => _handleLogin(context: context, isSignUp: true));
|
||||
|
|
@ -218,31 +235,20 @@ class LoginVM {
|
|||
@required String oneTimePassword,
|
||||
}) async {
|
||||
try {
|
||||
/*
|
||||
await GoogleOAuth.signOut();
|
||||
final signedIn = await GoogleOAuth.signIn((idToken, accessToken) {
|
||||
if (idToken.isEmpty || accessToken.isEmpty) {
|
||||
GoogleOAuth.signOut();
|
||||
completer.completeError(
|
||||
AppLocalization.of(context).anErrorOccurredTryAgain);
|
||||
} else {
|
||||
await oauth.logout();
|
||||
await oauth.login();
|
||||
final accessToken = await oauth.getAccessToken();
|
||||
store.dispatch(OAuthLoginRequest(
|
||||
completer: completer,
|
||||
idToken: idToken,
|
||||
idToken: '',
|
||||
accessToken: accessToken,
|
||||
url: _formatApiUrl(url),
|
||||
secret: secret.trim(),
|
||||
platform: getPlatform(context),
|
||||
provider: kOAuthProviderMicrosoft,
|
||||
oneTimePassword: oneTimePassword,
|
||||
));
|
||||
completer.future.then((_) => _handleLogin(context: context));
|
||||
}
|
||||
});
|
||||
if (!signedIn) {
|
||||
completer.completeError(
|
||||
AppLocalization.of(context).anErrorOccurredTryAgain);
|
||||
}
|
||||
*/
|
||||
} catch (error) {
|
||||
completer.completeError(error);
|
||||
print('## onMicrosoftLoginPressed: $error');
|
||||
|
|
|
|||
Loading…
Reference in New Issue