@@ -53,23 +53,15 @@ public class GoogleAuth extends Plugin {
53
53
54
54
private GoogleSignInClient googleSignInClient ;
55
55
56
- @ Override
57
- public void load () {
58
- String clientId = getConfig ().getString ("androidClientId" ,
59
- getConfig ().getString ("clientId" ,
60
- this .getContext ().getString (R .string .server_client_id )));
61
-
62
- boolean forceCodeForRefreshToken = getConfig ().getBoolean ("forceCodeForRefreshToken" , false );
63
-
56
+ public void loadSignInClient (String clientId , boolean forceCodeForRefreshToken , String [] scopeArray ) {
64
57
GoogleSignInOptions .Builder googleSignInBuilder = new GoogleSignInOptions .Builder (GoogleSignInOptions .DEFAULT_SIGN_IN )
65
- .requestIdToken (clientId )
66
- .requestEmail ();
58
+ .requestIdToken (clientId )
59
+ .requestEmail ();
67
60
68
61
if (forceCodeForRefreshToken ) {
69
62
googleSignInBuilder .requestServerAuthCode (clientId , true );
70
63
}
71
64
72
- String [] scopeArray = getConfig ().getArray ("scopes" , new String [] {});
73
65
Scope [] scopes = new Scope [scopeArray .length - 1 ];
74
66
Scope firstScope = new Scope (scopeArray [0 ]);
75
67
for (int i = 1 ; i < scopeArray .length ; i ++) {
@@ -81,6 +73,9 @@ public void load() {
81
73
googleSignInClient = GoogleSignIn .getClient (this .getContext (), googleSignInOptions );
82
74
}
83
75
76
+ @ Override
77
+ public void load () {}
78
+
84
79
@ PluginMethod ()
85
80
public void signIn (PluginCall call ) {
86
81
Intent signInIntent = googleSignInClient .getSignInIntent ();
@@ -177,6 +172,31 @@ public void onFailure(Exception e) {
177
172
178
173
@ PluginMethod ()
179
174
public void initialize (final PluginCall call ) {
175
+ // get data from config
176
+ String configClientId = getConfig ().getString ("androidClientId" ,
177
+ getConfig ().getString ("clientId" ,
178
+ this .getContext ().getString (R .string .server_client_id )));
179
+ boolean configForceCodeForRefreshToken = getConfig ().getBoolean ("forceCodeForRefreshToken" , false );
180
+ // need to get this as string so as to standardize with data from plugin call
181
+ String configScopeArray = getConfig ().getString ("scopes" , new String ());
182
+
183
+ // get client id from plugin call, fallback to be client id from config
184
+ String clientId = call .getData ().getString ("clientId" , configClientId );
185
+ // get forceCodeForRefreshToken from call, fallback to be from config
186
+ boolean forceCodeForRefreshToken = call .getData ().getBoolean ("grantOfflineAccess" , configForceCodeForRefreshToken );
187
+ // get scopes from call, fallback to be from config
188
+ String scopesStr = call .getData ().getString ("scopes" , configScopeArray );
189
+ // replace all the symbols from parsing array as string
190
+ // leaving only scopes delimited by commas
191
+ String replacedScopesStr = scopesStr
192
+ .replaceAll ("[\" \\ [\\ ] ]" , "" )
193
+ // this is for scopes that are in the form of a url
194
+ .replace ("\\ " , "" );
195
+
196
+ // scope to be in the form of an array
197
+ String [] scopeArray = replacedScopesStr .split ("," );
198
+
199
+ loadSignInClient (clientId , forceCodeForRefreshToken , scopeArray );
180
200
call .resolve ();
181
201
}
182
202
0 commit comments