Skip to content

Commit f2c2011

Browse files
authored
Merge pull request #111 from minifast/master
Set the locale and lock the time zone to UTC while formatting times
2 parents c978950 + eb4e592 commit f2c2011

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

android/src/main/java/com/reactlibrary/RNAppAuthModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Date;
3838
import java.util.HashMap;
3939
import java.util.Iterator;
40+
import java.util.Locale;
4041
import java.util.Map;
4142

4243
public class RNAppAuthModule extends ReactContextBaseJavaModule implements ActivityEventListener {
@@ -386,7 +387,8 @@ private WritableMap tokenResponseToMap(TokenResponse response) {
386387

387388
if (response.accessTokenExpirationTime != null) {
388389
Date expirationDate = new Date(response.accessTokenExpirationTime);
389-
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
390+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
391+
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
390392
String expirationDateString = formatter.format(expirationDate);
391393
map.putString("accessTokenExpirationDate", expirationDateString);
392394
}

ios/RNAppAuth.m

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ - (dispatch_queue_t)methodQueue
3636
additionalParameters: additionalParameters
3737
resolve: resolve
3838
reject: reject];
39-
39+
4040
} else {
4141
[OIDAuthorizationService discoverServiceConfigurationForIssuer:[NSURL URLWithString:issuer]
4242
completion:^(OIDServiceConfiguration *_Nullable configuration, NSError *_Nullable error) {
4343
if (!configuration) {
4444
reject(@"RNAppAuth Error", [error localizedDescription], error);
4545
return;
4646
}
47-
47+
4848
[self authorizeWithConfiguration: configuration
4949
redirectUrl: redirectUrl
5050
clientId: clientId
@@ -81,7 +81,7 @@ - (dispatch_queue_t)methodQueue
8181
additionalParameters: additionalParameters
8282
resolve: resolve
8383
reject: reject];
84-
84+
8585
} else {
8686
// otherwise hit up the discovery endpoint
8787
[OIDAuthorizationService discoverServiceConfigurationForIssuer:[NSURL URLWithString:issuer]
@@ -111,13 +111,13 @@ - (OIDServiceConfiguration *) createServiceConfiguration: (NSDictionary *) servi
111111
NSURL *authorizationEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"authorizationEndpoint"]];
112112
NSURL *tokenEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"tokenEndpoint"]];
113113
NSURL *registrationEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"registrationEndpoint"]];
114-
114+
115115
OIDServiceConfiguration *configuration =
116116
[[OIDServiceConfiguration alloc]
117117
initWithAuthorizationEndpoint:authorizationEndpoint
118118
tokenEndpoint:tokenEndpoint
119119
registrationEndpoint:registrationEndpoint];
120-
120+
121121
return configuration;
122122
}
123123

@@ -142,11 +142,11 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
142142
redirectURL:[NSURL URLWithString:redirectUrl]
143143
responseType:OIDResponseTypeCode
144144
additionalParameters:additionalParameters];
145-
146-
145+
146+
147147
// performs authentication request
148148
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
149-
149+
150150
appDelegate.currentAuthorizationFlow =
151151
[OIDAuthState authStateByPresentingAuthorizationRequest:request
152152
presentingViewController:appDelegate.window.rootViewController
@@ -157,7 +157,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
157157
} else {
158158
reject(@"RNAppAuth Error", [error localizedDescription], error);
159159
}
160-
160+
161161
}]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
162162
}
163163

@@ -174,7 +174,7 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
174174
additionalParameters: (NSDictionary *_Nullable) additionalParameters
175175
resolve:(RCTPromiseResolveBlock) resolve
176176
reject: (RCTPromiseRejectBlock) reject {
177-
177+
178178
OIDTokenRequest *tokenRefreshRequest =
179179
[[OIDTokenRequest alloc] initWithConfiguration:configuration
180180
grantType:@"refresh_token"
@@ -186,7 +186,7 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
186186
refreshToken:refreshToken
187187
codeVerifier:nil
188188
additionalParameters:additionalParameters];
189-
189+
190190
[OIDAuthorizationService performTokenRequest:tokenRefreshRequest
191191
callback:^(OIDTokenResponse *_Nullable response,
192192
NSError *_Nullable error) {
@@ -196,15 +196,17 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
196196
reject(@"RNAppAuth Error", [error localizedDescription], error);
197197
}
198198
}];
199-
199+
200200
}
201201

202202
/*
203203
* Take raw OIDTokenResponse and turn it to a token response format to pass to JavaScript caller
204204
*/
205205
- (NSDictionary*)formatResponse: (OIDTokenResponse*) response {
206206
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
207-
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
207+
dateFormat.timeZone = [NSTimeZone timeZoneWithAbbreviation: @"UTC"];
208+
[dateFormat setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
209+
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
208210

209211
return @{@"accessToken": response.accessToken ? response.accessToken : @"",
210212
@"accessTokenExpirationDate": response.accessTokenExpirationDate ? [dateFormat stringFromDate:response.accessTokenExpirationDate] : @"",

0 commit comments

Comments
 (0)