From 4882815c6ec3c65ad9902bb2fd1caa7a40c9ac4f Mon Sep 17 00:00:00 2001
From: Markin Igor <markin.io210@gmail.com>
Date: Wed, 24 Jul 2019 18:09:36 +0500
Subject: [PATCH] Rework serving OAuth params.

---
 lib/config.dart           | 21 +++++++++++----------
 lib/src/screens/home.dart | 13 +++++++------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/lib/config.dart b/lib/config.dart
index 1e9fde2..d6ff251 100644
--- a/lib/config.dart
+++ b/lib/config.dart
@@ -5,14 +5,15 @@ enum Flavor {
 
 class Config {
   static Flavor appFlavor;
-}
-
-const String APP_HOST = "https://demo1.vereign.com";
+  static const DEFAULT_APP_HOST = "https://demo1.vereign.com";
 
-/* OAuth */
-const String CLIENT_ID = "123123";
-const String CLIENT_SECRET = "123123";
-
-const String REDIRECT_URL = "app://com.vereign.app/oauth2";
-const String AUTH_ENDPOINT = "$APP_HOST/api/oauth2/authorize";
-const String TOKEN_ENDPOINT = "$APP_HOST/api/oauth2/token";
\ No newline at end of file
+  static Map<String, String> getOAuthParams({host = DEFAULT_APP_HOST}) {
+    return {
+      "clientId": "123123",
+      "clientSecret": "123123",
+      "redirectUrl": "app://com.vereign.app/oauth2",
+      "authEndpoint": "$host/api/oauth2/authorize",
+      "tokenEndpoint": "$host/api/oauth2/token",
+    };
+  }
+}
diff --git a/lib/src/screens/home.dart b/lib/src/screens/home.dart
index 96cf44f..48bdfc0 100644
--- a/lib/src/screens/home.dart
+++ b/lib/src/screens/home.dart
@@ -20,7 +20,6 @@ class Home extends StatefulWidget {
 const hosts = [
   'https://rosengeorgiev.dev.vereign.com',
   'https://borisdimitrov.dev.vereign.com',
-  'https://app.vereign.com',
   'https://integration.vereign.com',
   'https://staging.vereign.com',
   'https://demo1.vereign.com',
@@ -39,7 +38,7 @@ const hosts = [
 ];
 
 class _HomeState extends State<Home> {
-  String _host = Config.appFlavor == Flavor.DEVELOPMENT ? hosts[0] : APP_HOST;
+  String _host = Config.appFlavor == Flavor.DEVELOPMENT ? hosts[0] : Config.DEFAULT_APP_HOST;
 
   @override
   initState() {
@@ -104,15 +103,17 @@ class _HomeState extends State<Home> {
   }
 
   startOAuth() {
+    var params = Config.getOAuthParams(host: _host);
+
     FlutterAppAuthWrapper.startAuth(
       AuthConfig(
-        clientId: CLIENT_ID,
-        clientSecret: CLIENT_SECRET,
-        redirectUrl: REDIRECT_URL,
+        clientId: params["clientId"],
+        clientSecret: params["clientSecret"],
+        redirectUrl: params["redirectUrl"],
         state: "login",
         prompt: "consent",
         endpoint: AuthEndpoint(
-            auth: AUTH_ENDPOINT, token: TOKEN_ENDPOINT),
+            auth: params["authEndpoint"], token: params["tokenEndpoint"]),
         scopes: [
           "user_account_status",
           "user_territory",
-- 
GitLab