diff options
author | Zsika Phillip <protocol86@users.noreply.github.com> | 2018-04-20 18:58:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-20 18:58:23 -0700 |
commit | b2cf8c6d3df3ebe792c4b3932f05ddfc7f477959 (patch) | |
tree | 814c63b2490dd5d5afbf18f978d31f8ec5eaa012 /Firebase/Auth | |
parent | e46f27a2c4cab235883eb1da39e7a34b2d66da27 (diff) |
Fixes base64URL encoding (#1161)
* Fixes base64URL encoding
* Addresses comments
* Addresses comment
Diffstat (limited to 'Firebase/Auth')
-rw-r--r-- | Firebase/Auth/Source/FIRUser.m | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index 8dc5739..ea48267 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -845,8 +845,18 @@ static void callInMainThreadWithAuthDataResultAndError( - (FIRAuthTokenResult *)parseIDToken:(NSString *)token error:(NSError **)error { *error = nil; NSArray *tokenStringArray = [token componentsSeparatedByString:@"."]; + // The token payload is always the second index of the array. - NSMutableString *tokenPayload = [[NSMutableString alloc] initWithString:tokenStringArray[1]]; + NSString *idToken = tokenStringArray[1]; + + // Convert the base64URL encoded string to a base64 encoded string. + // Replace "_" with "/" + NSMutableString *tokenPayload = + [[idToken stringByReplacingOccurrencesOfString:@"_" withString:@"/"] mutableCopy]; + + // Replace "-" with "+" + tokenPayload = + [[tokenPayload stringByReplacingOccurrencesOfString:@"-" withString:@"+"] mutableCopy]; // Pad the token payload with "=" signs if the payload's length is not a multiple of 4. while ((tokenPayload.length % 4) != 0) { |