Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
feat: more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Feb 27, 2022
1 parent ccb1c47 commit f99413a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:url_launcher/link.dart';
import 'package:url_strategy/url_strategy.dart';
import 'package:window_manager/window_manager.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:simple_auth_flutter/simple_auth_flutter.dart';

void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -128,6 +129,7 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
@override
void initState() {
super.initState();
SimpleAuthFlutter.init(context);
}

int index = 0;
Expand Down
21 changes: 21 additions & 0 deletions lib/src/models/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:simple_auth/simple_auth.dart' as simpleAuth;
import '../../config.dart';

enum Reason {
//"The account is not satisfied with this action"
Expand All @@ -15,8 +17,24 @@ class MSAuthError extends Error {
MSAuthError(this.reason);
}

class TAzure extends simpleAuth.AzureADApi implements showAuthenticator {
TAzure(String identifier, String clientId, String tokenUrl, String resource,
String authorizationUrl, String redirectUrl)
: super(identifier, clientId, tokenUrl, resource, authorizationUrl,
redirectUrl);
}

class MSAuth {
static const MICROSOFT_CLIENT_ID = "e2d21d17-35c3-46e6-9afd-f475b0f08c46";
static const AZURE_TENNANT = "f8cdef31-a31e-4b4a-93e4-5f571e91255a";
static final simpleAuth.AzureADApi azureApi = simpleAuth.AzureADApi(
"azure",
MICROSOFT_CLIENT_ID,
"https://login.microsoftonline.com/$AZURE_TENNANT/oauth2/authorize",
"https://login.microsoftonline.com/$AZURE_TENNANT/oauth2/token",
"https://management.azure.com/",
"redirecturl");

static Future<Map> authCode2AuthToken(String code) async {
var map = <String, dynamic>{};
map["code"] = code;
Expand Down Expand Up @@ -172,6 +190,9 @@ class MSAuth {
return false;
}
// updateAccountToken(account, mcToken, params["refresh_token"]);
Config.preferences?.setString("account", json.encode(account));
Config.preferences?.setString("mcToken", json.encode(mcToken));
Config.preferences?.setString("refresh_token", params["refresh_token"]);
return true;
} catch (e) {
return false;
Expand Down
7 changes: 6 additions & 1 deletion lib/src/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

import 'package:fluent_ui/fluent_ui.dart';
import 'package:tmodinstaller/src/models/auth.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:social_login_buttons/social_login_buttons.dart';

Expand All @@ -26,7 +27,11 @@ class _LoginStatefulWidgetState extends State<LoginStatefulWidget> {
return Center(
child: SocialLoginButton(
buttonType: SocialLoginButtonType.microsoft,
onPressed: () {},
onPressed: () async {
var success = await MSAuth.azureApi.authenticate();
print(success?.toJson());
// showMessage("Logged in success: $success");
},
),
);
// return Padding(
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
simple_auth:
dependency: "direct main"
description:
name: simple_auth
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
simple_auth_flutter:
dependency: "direct main"
description:
name: simple_auth_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dependencies:
isar: 2.2.1
isar_flutter_libs: 2.2.1 # contains the binarie
social_login_buttons: ^1.0.6+2
simple_auth: ^2.0.10
simple_auth_flutter: ^2.0.11

dev_dependencies:
# flutter_test:
Expand Down

0 comments on commit f99413a

Please sign in to comment.