@@ -53,23 +53,15 @@ public class GoogleAuth extends Plugin {
5353
5454 private GoogleSignInClient googleSignInClient ;
5555
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 ) {
6457 GoogleSignInOptions .Builder googleSignInBuilder = new GoogleSignInOptions .Builder (GoogleSignInOptions .DEFAULT_SIGN_IN )
65- .requestIdToken (clientId )
66- .requestEmail ();
58+ .requestIdToken (clientId )
59+ .requestEmail ();
6760
6861 if (forceCodeForRefreshToken ) {
6962 googleSignInBuilder .requestServerAuthCode (clientId , true );
7063 }
7164
72- String [] scopeArray = getConfig ().getArray ("scopes" , new String [] {});
7365 Scope [] scopes = new Scope [scopeArray .length - 1 ];
7466 Scope firstScope = new Scope (scopeArray [0 ]);
7567 for (int i = 1 ; i < scopeArray .length ; i ++) {
@@ -81,6 +73,9 @@ public void load() {
8173 googleSignInClient = GoogleSignIn .getClient (this .getContext (), googleSignInOptions );
8274 }
8375
76+ @ Override
77+ public void load () {}
78+
8479 @ PluginMethod ()
8580 public void signIn (PluginCall call ) {
8681 Intent signInIntent = googleSignInClient .getSignInIntent ();
@@ -177,6 +172,31 @@ public void onFailure(Exception e) {
177172
178173 @ PluginMethod ()
179174 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 );
180200 call .resolve ();
181201 }
182202
0 commit comments