File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -192,18 +192,25 @@ static void GoogleSignIn_Signout(HandleRef self)
192192
193193 internal static string GoogleSignIn_GetUserId ( HandleRef self )
194194 {
195+ string idTokenFull = null ;
195196 try
196197 {
197- var idTokenPart = googleIdTokenCredential ? . Call < string > ( "getIdToken" ) ? . Split ( '.' ) ? . ElementAtOrDefault ( 1 ) ;
198+ idTokenFull = googleIdTokenCredential ? . Call < string > ( "getIdToken" ) ;
199+ var idTokenPart = idTokenFull ? . Split ( '.' ) ? . ElementAtOrDefault ( 1 ) ;
198200 if ( ! ( idTokenPart ? . Length is int length && length > 1 ) )
199201 return null ;
200202
203+ // Replace URL-safe characters and fix padding
204+ idTokenPart = idTokenPart . Replace ( '-' , '+' ) . Replace ( '_' , '/' ) ;
201205 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 ) ;
203209 return jobj ? [ "sub" ] ? . ToString ( ) ;
204210 }
205211 catch ( Exception e )
206212 {
213+ // Debug.LogException(new Exception($"GoogleSignIn_GetUserId.idTokenFull {idTokenFull}"));
207214 Debug . LogException ( e ) ;
208215 return null ;
209216 }
You can’t perform that action at this time.
0 commit comments