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 kProductPlanEnterprise10 = 'v1_enterprise_10_yearly';
|
||||||
const String kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
const String kProductPlanEnterprise20 = 'v1_enterprise_20_yearly';
|
||||||
|
|
||||||
|
const String kOAuthProviderMicrosoft = 'microsoft';
|
||||||
|
const String kOAuthProviderGoogle = 'google';
|
||||||
|
|
||||||
const kProductPlans = [
|
const kProductPlans = [
|
||||||
kProductPlanPro,
|
kProductPlanPro,
|
||||||
kProductPlanEnterprise2,
|
kProductPlanEnterprise2,
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ class AuthRepository {
|
||||||
@required String idToken,
|
@required String idToken,
|
||||||
@required String accessToken,
|
@required String accessToken,
|
||||||
@required String referralCode,
|
@required String referralCode,
|
||||||
|
@required String provider,
|
||||||
}) async {
|
}) async {
|
||||||
final credentials = {
|
final credentials = {
|
||||||
'terms_of_service': true,
|
'terms_of_service': true,
|
||||||
|
|
@ -61,7 +62,7 @@ class AuthRepository {
|
||||||
'token_name': _tokenName,
|
'token_name': _tokenName,
|
||||||
'id_token': idToken,
|
'id_token': idToken,
|
||||||
//'access_token': accessToken,
|
//'access_token': accessToken,
|
||||||
'provider': 'google',
|
'provider': provider,
|
||||||
'platform': getPlatformName(),
|
'platform': getPlatformName(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -102,10 +103,11 @@ class AuthRepository {
|
||||||
@required String accessToken,
|
@required String accessToken,
|
||||||
@required String url,
|
@required String url,
|
||||||
@required String secret,
|
@required String secret,
|
||||||
@required String platform}) async {
|
@required String platform,
|
||||||
|
@required String provider}) async {
|
||||||
final credentials = {
|
final credentials = {
|
||||||
'id_token': idToken,
|
'id_token': idToken,
|
||||||
'provider': 'google',
|
'provider': provider,
|
||||||
};
|
};
|
||||||
url = formatApiUrl(url) + '/oauth_login';
|
url = formatApiUrl(url) + '/oauth_login';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class OAuthLoginRequest implements StartLoading {
|
||||||
@required this.url,
|
@required this.url,
|
||||||
@required this.secret,
|
@required this.secret,
|
||||||
@required this.platform,
|
@required this.platform,
|
||||||
|
@required this.provider,
|
||||||
@required this.oneTimePassword,
|
@required this.oneTimePassword,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ class OAuthLoginRequest implements StartLoading {
|
||||||
final String url;
|
final String url;
|
||||||
final String secret;
|
final String secret;
|
||||||
final String platform;
|
final String platform;
|
||||||
|
final String provider;
|
||||||
final String oneTimePassword;
|
final String oneTimePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,11 +132,13 @@ class OAuthSignUpRequest implements StartLoading {
|
||||||
@required this.completer,
|
@required this.completer,
|
||||||
@required this.idToken,
|
@required this.idToken,
|
||||||
@required this.accessToken,
|
@required this.accessToken,
|
||||||
|
@required this.provider,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Completer completer;
|
final Completer completer;
|
||||||
final String idToken;
|
final String idToken;
|
||||||
final String accessToken;
|
final String accessToken;
|
||||||
|
final String provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserVerifiedPassword {}
|
class UserVerifiedPassword {}
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ Middleware<AppState> _createOAuthLoginRequest(AuthRepository repository) {
|
||||||
accessToken: action.accessToken,
|
accessToken: action.accessToken,
|
||||||
url: action.url,
|
url: action.url,
|
||||||
secret: action.secret,
|
secret: action.secret,
|
||||||
|
provider: action.provider,
|
||||||
platform: action.platform)
|
platform: action.platform)
|
||||||
.then((data) {
|
.then((data) {
|
||||||
_saveAuthLocal(action.url);
|
_saveAuthLocal(action.url);
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,16 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
// Flutter imports:
|
// Flutter imports:
|
||||||
|
import 'package:aad_oauth/model/config.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
// Package imports:
|
// Package imports:
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:invoiceninja_flutter/main_app.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:aad_oauth/aad_oauth.dart';
|
||||||
|
|
||||||
// Project imports:
|
// Project imports:
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
|
|
@ -106,6 +110,17 @@ class LoginVM {
|
||||||
final Function(BuildContext, Completer<Null> completer)
|
final Function(BuildContext, Completer<Null> completer)
|
||||||
onMicrosoftSignUpPressed;
|
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) {
|
static LoginVM fromStore(Store<AppState> store) {
|
||||||
void _handleLogin({BuildContext context, bool isSignUp = false}) {
|
void _handleLogin({BuildContext context, bool isSignUp = false}) {
|
||||||
final layout = calculateLayout(context);
|
final layout = calculateLayout(context);
|
||||||
|
|
@ -168,6 +183,7 @@ class LoginVM {
|
||||||
url: _formatApiUrl(url),
|
url: _formatApiUrl(url),
|
||||||
secret: secret.trim(),
|
secret: secret.trim(),
|
||||||
platform: getPlatform(context),
|
platform: getPlatform(context),
|
||||||
|
provider: kOAuthProviderGoogle,
|
||||||
oneTimePassword: oneTimePassword,
|
oneTimePassword: oneTimePassword,
|
||||||
));
|
));
|
||||||
completer.future.then((_) => _handleLogin(context: context));
|
completer.future.then((_) => _handleLogin(context: context));
|
||||||
|
|
@ -196,6 +212,7 @@ class LoginVM {
|
||||||
completer: completer,
|
completer: completer,
|
||||||
idToken: idToken,
|
idToken: idToken,
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
|
provider: kOAuthProviderGoogle,
|
||||||
));
|
));
|
||||||
completer.future
|
completer.future
|
||||||
.then((_) => _handleLogin(context: context, isSignUp: true));
|
.then((_) => _handleLogin(context: context, isSignUp: true));
|
||||||
|
|
@ -218,31 +235,20 @@ class LoginVM {
|
||||||
@required String oneTimePassword,
|
@required String oneTimePassword,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
/*
|
await oauth.logout();
|
||||||
await GoogleOAuth.signOut();
|
await oauth.login();
|
||||||
final signedIn = await GoogleOAuth.signIn((idToken, accessToken) {
|
final accessToken = await oauth.getAccessToken();
|
||||||
if (idToken.isEmpty || accessToken.isEmpty) {
|
store.dispatch(OAuthLoginRequest(
|
||||||
GoogleOAuth.signOut();
|
completer: completer,
|
||||||
completer.completeError(
|
idToken: '',
|
||||||
AppLocalization.of(context).anErrorOccurredTryAgain);
|
accessToken: accessToken,
|
||||||
} else {
|
url: _formatApiUrl(url),
|
||||||
store.dispatch(OAuthLoginRequest(
|
secret: secret.trim(),
|
||||||
completer: completer,
|
platform: getPlatform(context),
|
||||||
idToken: idToken,
|
provider: kOAuthProviderMicrosoft,
|
||||||
accessToken: accessToken,
|
oneTimePassword: oneTimePassword,
|
||||||
url: _formatApiUrl(url),
|
));
|
||||||
secret: secret.trim(),
|
completer.future.then((_) => _handleLogin(context: context));
|
||||||
platform: getPlatform(context),
|
|
||||||
oneTimePassword: oneTimePassword,
|
|
||||||
));
|
|
||||||
completer.future.then((_) => _handleLogin(context: context));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!signedIn) {
|
|
||||||
completer.completeError(
|
|
||||||
AppLocalization.of(context).anErrorOccurredTryAgain);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
completer.completeError(error);
|
completer.completeError(error);
|
||||||
print('## onMicrosoftLoginPressed: $error');
|
print('## onMicrosoftLoginPressed: $error');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue