File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -192,18 +192,25 @@ static void GoogleSignIn_Signout(HandleRef self)
192
192
193
193
internal static string GoogleSignIn_GetUserId ( HandleRef self )
194
194
{
195
+ string idTokenFull = null ;
195
196
try
196
197
{
197
- var idTokenPart = googleIdTokenCredential ? . Call < string > ( "getIdToken" ) ? . Split ( '.' ) ? . ElementAtOrDefault ( 1 ) ;
198
+ idTokenFull = googleIdTokenCredential ? . Call < string > ( "getIdToken" ) ;
199
+ var idTokenPart = idTokenFull ? . Split ( '.' ) ? . ElementAtOrDefault ( 1 ) ;
198
200
if ( ! ( idTokenPart ? . Length is int length && length > 1 ) )
199
201
return null ;
200
202
203
+ // Replace URL-safe characters and fix padding
204
+ idTokenPart = idTokenPart . Replace ( '-' , '+' ) . Replace ( '_' , '/' ) ;
201
205
string fill = new string ( '=' , ( 4 - ( idTokenPart . Length % 4 ) ) % 4 ) ;
202
- var jobj = Newtonsoft . Json . Linq . JObject . Parse ( Encoding . UTF8 . GetString ( Convert . FromBase64String ( idTokenPart + fill ) ) ) ;
206
+ var idTokenFromBase64 = Convert . FromBase64String ( idTokenPart + fill ) ;
207
+ var idToken = Encoding . UTF8 . GetString ( idTokenFromBase64 ) ;
208
+ var jobj = Newtonsoft . Json . Linq . JObject . Parse ( idToken ) ;
203
209
return jobj ? [ "sub" ] ? . ToString ( ) ;
204
210
}
205
211
catch ( Exception e )
206
212
{
213
+ // Debug.LogException(new Exception($"GoogleSignIn_GetUserId.idTokenFull {idTokenFull}"));
207
214
Debug . LogException ( e ) ;
208
215
return null ;
209
216
}
You can’t perform that action at this time.
0 commit comments