Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion android/src/main/java/com/reactlibrary/RNAppAuthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

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

if (response.accessTokenExpirationTime != null) {
Date expirationDate = new Date(response.accessTokenExpirationTime);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String expirationDateString = formatter.format(expirationDate);
map.putString("accessTokenExpirationDate", expirationDateString);
}
Expand Down
28 changes: 15 additions & 13 deletions ios/RNAppAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ - (dispatch_queue_t)methodQueue
additionalParameters: additionalParameters
resolve: resolve
reject: reject];

} else {
[OIDAuthorizationService discoverServiceConfigurationForIssuer:[NSURL URLWithString:issuer]
completion:^(OIDServiceConfiguration *_Nullable configuration, NSError *_Nullable error) {
if (!configuration) {
reject(@"RNAppAuth Error", [error localizedDescription], error);
return;
}

[self authorizeWithConfiguration: configuration
redirectUrl: redirectUrl
clientId: clientId
Expand Down Expand Up @@ -81,7 +81,7 @@ - (dispatch_queue_t)methodQueue
additionalParameters: additionalParameters
resolve: resolve
reject: reject];

} else {
// otherwise hit up the discovery endpoint
[OIDAuthorizationService discoverServiceConfigurationForIssuer:[NSURL URLWithString:issuer]
Expand Down Expand Up @@ -111,13 +111,13 @@ - (OIDServiceConfiguration *) createServiceConfiguration: (NSDictionary *) servi
NSURL *authorizationEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"authorizationEndpoint"]];
NSURL *tokenEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"tokenEndpoint"]];
NSURL *registrationEndpoint = [NSURL URLWithString: [serviceConfiguration objectForKey:@"registrationEndpoint"]];

OIDServiceConfiguration *configuration =
[[OIDServiceConfiguration alloc]
initWithAuthorizationEndpoint:authorizationEndpoint
tokenEndpoint:tokenEndpoint
registrationEndpoint:registrationEndpoint];

return configuration;
}

Expand All @@ -142,11 +142,11 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
redirectURL:[NSURL URLWithString:redirectUrl]
responseType:OIDResponseTypeCode
additionalParameters:additionalParameters];


// performs authentication request
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

appDelegate.currentAuthorizationFlow =
[OIDAuthState authStateByPresentingAuthorizationRequest:request
presentingViewController:appDelegate.window.rootViewController
Expand All @@ -157,7 +157,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
} else {
reject(@"RNAppAuth Error", [error localizedDescription], error);
}

}]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
}

Expand All @@ -174,7 +174,7 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
additionalParameters: (NSDictionary *_Nullable) additionalParameters
resolve:(RCTPromiseResolveBlock) resolve
reject: (RCTPromiseRejectBlock) reject {

OIDTokenRequest *tokenRefreshRequest =
[[OIDTokenRequest alloc] initWithConfiguration:configuration
grantType:@"refresh_token"
Expand All @@ -186,7 +186,7 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
refreshToken:refreshToken
codeVerifier:nil
additionalParameters:additionalParameters];

[OIDAuthorizationService performTokenRequest:tokenRefreshRequest
callback:^(OIDTokenResponse *_Nullable response,
NSError *_Nullable error) {
Expand All @@ -196,15 +196,17 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
reject(@"RNAppAuth Error", [error localizedDescription], error);
}
}];

}

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

return @{@"accessToken": response.accessToken ? response.accessToken : @"",
@"accessTokenExpirationDate": response.accessTokenExpirationDate ? [dateFormat stringFromDate:response.accessTokenExpirationDate] : @"",
Expand Down