7
7
import android .util .Log ;
8
8
9
9
import com .google .gson .Gson ;
10
+ import com .google .gson .JsonSyntaxException ;
10
11
11
12
import com .facebook .react .bridge .Arguments ;
12
13
import com .facebook .react .bridge .Callback ;
@@ -400,18 +401,36 @@ private WritableMap accessTokenResponse(
400
401
) {
401
402
WritableMap resp = Arguments .createMap ();
402
403
WritableMap response = Arguments .createMap ();
403
- Map accessTokenMap = new Gson ().fromJson (accessToken .getRawResponse (), Map .class );
404
404
405
405
Log .d (TAG , "Credential raw response: " + accessToken .getRawResponse ());
406
-
406
+
407
+ /* Some things return as JSON, some as x-www-form-urlencoded (querystring) */
408
+
409
+ Map accessTokenMap = null ;
410
+ try {
411
+ accessTokenMap = new Gson ().fromJson (accessToken .getRawResponse (), Map .class );
412
+ } catch (JsonSyntaxException e ) {
413
+ /*
414
+ failed to parse as JSON, so turn it into a HashMap which looks like the one we'd
415
+ get back from the JSON parser, so the rest of the code continues unchanged.
416
+ */
417
+ Log .d (TAG , "Credential looks like a querystring; parsing as such" );
418
+ accessTokenMap = new HashMap ();
419
+ accessTokenMap .put ("user_id" , accessToken .getParameter ("user_id" ));
420
+ accessTokenMap .put ("oauth_token_secret" , accessToken .getParameter ("oauth_token_secret" ));
421
+ accessTokenMap .put ("token_type" , accessToken .getParameter ("token_type" ));
422
+ }
423
+
424
+
407
425
resp .putString ("status" , "ok" );
408
426
resp .putBoolean ("authorized" , true );
409
427
resp .putString ("provider" , providerName );
410
- String uuid = (String ) accessTokenMap .get ("user_id" );
428
+
429
+ String uuid = accessToken .getParameter ("user_id" );
411
430
response .putString ("uuid" , uuid );
412
- String oauthTokenSecret = (String ) accessTokenMap . get ("oauth_token_secret" );
431
+ String oauthTokenSecret = (String ) accessToken . getParameter ("oauth_token_secret" );
413
432
414
- String tokenType = (String ) accessTokenMap . get ("token_type" );
433
+ String tokenType = (String ) accessToken . getParameter ("token_type" );
415
434
if (tokenType == null ) {
416
435
tokenType = "Bearer" ;
417
436
}
@@ -422,7 +441,6 @@ private WritableMap accessTokenResponse(
422
441
credentials .putString ("access_token" , accessToken .getToken ());
423
442
credentials .putString ("access_token_secret" , oauthTokenSecret );
424
443
credentials .putString ("type" , tokenType );
425
- // credentials.putString("scope", accessToken.getScope());
426
444
credentials .putString ("consumerKey" , consumerKey );
427
445
428
446
response .putMap ("credentials" , credentials );
@@ -440,26 +458,21 @@ private WritableMap accessTokenResponse(
440
458
) {
441
459
WritableMap resp = Arguments .createMap ();
442
460
WritableMap response = Arguments .createMap ();
443
- Map accessTokenMap = new Gson ().fromJson (accessToken .getRawResponse (), Map .class );
444
461
445
462
resp .putString ("status" , "ok" );
446
463
resp .putBoolean ("authorized" , true );
447
464
resp .putString ("provider" , providerName );
448
- try {
449
- String uuid = (String ) accessTokenMap .get ("user_id" );
450
- response .putString ("uuid" , uuid );
451
- } catch (Exception ex ) {
452
- Log .e (TAG , "Exception while getting the access token" );
453
- ex .printStackTrace ();
454
- }
465
+
466
+ String uuid = accessToken .getParameter ("user_id" );
467
+ response .putString ("uuid" , uuid );
455
468
456
469
WritableMap credentials = Arguments .createMap ();
457
470
Log .d (TAG , "Credential raw response: " + accessToken .getRawResponse ());
458
471
459
472
credentials .putString ("accessToken" , accessToken .getAccessToken ());
460
473
String authHeader ;
461
474
462
- String tokenType = ( String ) accessTokenMap . get ( "token_type" );
475
+ String tokenType = accessToken . getTokenType ( );
463
476
if (tokenType == null ) {
464
477
tokenType = "Bearer" ;
465
478
}
@@ -470,7 +483,7 @@ private WritableMap accessTokenResponse(
470
483
}
471
484
472
485
String clientID = (String ) cfg .get ("client_id" );
473
- String idToken = ( String ) accessTokenMap . get ("id_token" );
486
+ String idToken = accessToken . getParameter ("id_token" );
474
487
475
488
authHeader = tokenType + " " + accessToken .getAccessToken ();
476
489
credentials .putString ("authorizationHeader" , authHeader );
0 commit comments