aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth/Source/FIRUser.m
diff options
context:
space:
mode:
Diffstat (limited to 'Firebase/Auth/Source/FIRUser.m')
-rw-r--r--Firebase/Auth/Source/FIRUser.m12
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) {