Skip to content

Commit 9f899c5

Browse files
committed
Changes for v1.3.0
1 parent 589d839 commit 9f899c5

14 files changed

+643
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# cordova-plugin-oracle-idm-auth 1.2.0
1+
# cordova-plugin-oracle-idm-auth 1.3.0
22

33
## About the cordova-plugin-oracle-idm-auth
44
The plugin provides authentication and authorization functionality for cordova based mobile applications,

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 1.3.0 (3 Dec, 2019)
4+
* API to control buttons shown on webview for OAuth usecase.
5+
* Ability to store data into local authenticator secure keystore.
6+
37
## 1.2.0 (7 Aug, 2019)
48
* API to control buttons shown on webview for WebSSO usecase.
59
* Improvements for OAuth and OpenID usecases where login page is opened in an external browser by using in-app browser.

md/error-codes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,7 @@ P1018 | Error while enabling local authenticator.
158158
P1019 | Either the device does not support biometric or is not enrolled.
159159
P1020 | Attempt to change PIN when PIN is not enabled.
160160
P1021 | Error while getting enabled local authentications.
161-
P1022 | Unable to find the local authenticator required for the operation.
161+
P1022 | Saving value to secured storage failed.
162+
P1023 | Saving value to default storage failed.
163+
P1024 | Getting value from secured storage failed.
164+
P1025 | Getting value from default storage failed.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-oracle-idm-auth",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Provides authentication and authorization functionality using the Oracle IDM SDK, supporting standard protocols like Basic Auth, OAUTH, OpenID Connect and WebSSO.",
55
"cordova": {
66
"id": "cordova-plugin-oracle-idm-auth",

src/ios/src/IdmAuthentication.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,14 @@ - (NSMutableDictionary*) headersForOAuth: (NSSet*) scopes
696696
}
697697
NSArray* tokens = [context tokensForScopes:scopes];
698698
NSString* tokenValue;
699+
NSDate* sessionExpiryDate;
699700

700701
if ([tokens count] > 0) {
701702
tokenValue = ((OMToken*) [tokens objectAtIndex:0]).tokenValue;
703+
sessionExpiryDate = ((OMToken*) [tokens objectAtIndex:0]).sessionExpiryDate;
704+
702705
headers[@"Authorization"] = [NSString stringWithFormat:@"Bearer %@", tokenValue];
706+
headers[@"ExpiryTime"] = [NSString stringWithFormat:@"%@", sessionExpiryDate];
703707
}
704708

705709
return headers;

src/ios/src/IdmAuthenticationPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
3737
- (void) authenticateBiometric:(CDVInvokedUrlCommand *) command;
3838
- (void) changePin:(CDVInvokedUrlCommand *) command;
3939
- (void) getLocalAuthSupportInfo:(CDVInvokedUrlCommand *) command;
40+
- (void) getPreference:(CDVInvokedUrlCommand *) command;
41+
- (void) setPreference:(CDVInvokedUrlCommand *) command;
4042
@end
4143

4244

src/ios/src/IdmAuthenticationPlugin.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ - (void) getLocalAuthSupportInfo:(CDVInvokedUrlCommand *) command {
298298
delegate:self.commandDelegate];
299299
}
300300

301+
- (void) getPreference:(CDVInvokedUrlCommand *) command {
302+
[[LocalAuthenticator sharedInstance] getPreference:command
303+
delegate:self.commandDelegate];
304+
}
305+
306+
- (void) setPreference:(CDVInvokedUrlCommand *) command {
307+
[[LocalAuthenticator sharedInstance] setPreference:command
308+
delegate:self.commandDelegate];
309+
}
310+
301311
/**
302312
* Validates the arguments passed from javascript layer.
303313
*/

src/ios/src/LocalAuthenticator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
-(void) authenticatePin:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate;
1919
-(void) changePin:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate;
2020
-(void) getLocalAuthSupportInfo:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate;
21+
-(void) getPreference:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate;
22+
-(void) setPreference:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate;
2123
@end

src/ios/src/LocalAuthenticator.m

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
#import "LocalAuthenticator.h"
66
#import "IdmAuthenticationPlugin.h"
77
#import "IDMMobileSDKv2Library.h"
8+
#import "OMSecureStorage.h"
9+
810
@import LocalAuthentication;
911

1012
#define LOCAL_AUTH_BIOMETRIC @"cordova.plugins.IdmAuthFlows.Biometric"
1113
#define LOCAL_AUTH_FINGERPRINT @"cordova.plugins.IdmAuthFlows.Fingerprint"
1214
#define LOCAL_AUTH_PIN @"cordova.plugins.IdmAuthFlows.PIN"
15+
#define LOCAL_AUTH_DEFAULT @"cordova.plugins.IdmAuthFlows.Default"
16+
#define DEFAULT_AUTH_ID @"DefaultAuthInstance"
1317
#define FALLBACK_RESULT @"fallback"
1418
#define PROMPT_MESSAGE @"promptMessage"
1519
#define PIN_FALLBACK_BUTTON_LABEL @"pinFallbackButtonLabel"
@@ -28,6 +32,10 @@
2832
#define DISABLE_PIN_BIOMETRIC_ENABLED @"P1017"
2933
#define ERROR_ENABLING_AUTHENTICATOR @"P1018"
3034
#define BIOMETRIC_NOT_ENABLED @"P1019"
35+
#define SAVING_VALUE_TO_SECURED_STORAGE_FAILED @"P1022"
36+
#define SAVING_VALUE_TO_DEFAULT_STORAGE_FAILED @"P1023"
37+
#define GETTING_VALUE_FROM_SECURED_STORAGE_FAILED @"P1024"
38+
#define GETTING_VALUE_FROM_DEFAULT_STORAGE_FAILED @"P1025"
3139

3240
#ifdef DEBUG
3341
# define IdmLog(...) NSLog(__VA_ARGS__)
@@ -41,6 +49,8 @@
4149
@interface LocalAuthenticator()<OMBiometricFallbackDelegate>
4250

4351
@property (nonatomic, assign) Boolean authenticatedViaPin;
52+
@property (nonatomic, assign) Boolean defaultAuthenticationEnabled;
53+
4454
@property (nonatomic, strong) OMFallbackAuthenticationCompletionBlock fallbackHandler;
4555

4656
@property (nonatomic, strong, nullable) CDVCommandDelegateImpl* biometricAuthDelegate;
@@ -56,6 +66,7 @@ +(LocalAuthenticator*) sharedInstance {
5666
sharedManager = [OMLocalAuthenticationManager sharedManager];
5767
[sharedManager useBiometricInsteadOfTouchID:YES];
5868
shared = [[LocalAuthenticator alloc] init];
69+
shared.defaultAuthenticationEnabled = [shared enableDefaultAuthenticator];
5970
});
6071

6172
return shared;
@@ -68,6 +79,37 @@ -(void) enabledLocalAuthsPrimaryFirst:(CDVInvokedUrlCommand*)command delegate:(C
6879
[commandDelegate sendPluginResult:result callbackId:command.callbackId];
6980
}
7081

82+
- (BOOL) enableDefaultAuthenticator {
83+
NSString* authId = DEFAULT_AUTH_ID;
84+
NSError* enableError = nil;
85+
NSString* authenticatorName = LOCAL_AUTH_DEFAULT;
86+
87+
OMAuthenticator* authenticator = [self getAuthenticator:authId authenticatorName:authenticatorName];
88+
if (authenticator != nil) {
89+
IdmLog(@"Authenticator is already enabled for type %@", authenticatorName);
90+
return YES;
91+
}
92+
93+
NSString* instanceId = [self getInstanceId:authId authenticatorName:authenticatorName];
94+
[self registerAuthenticatorIfNeeded:authenticatorName error:&enableError];
95+
96+
if (!enableError) {
97+
if ([sharedManager enableAuthentication:authenticatorName instanceId:instanceId error:&enableError]) {
98+
OMAuthenticator* authenticator = [self getAuthenticator:authId authenticatorName:authenticatorName];
99+
[authenticator authenticate:nil error:&enableError];
100+
if (authenticator == nil) {
101+
IdmLog(@"Something went wrong while enabling Default Authenticator.");
102+
return NO;
103+
}
104+
}
105+
}
106+
if (enableError) {
107+
IdmLog(@"Error Registering Default Authenticator");
108+
return NO;
109+
}
110+
return YES;
111+
}
112+
71113
-(void) enable:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate {
72114
NSError* enableError = nil;
73115
NSString* authId = command.arguments[0];
@@ -177,6 +219,86 @@ -(void) disable:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*
177219
callbackId:command.callbackId];
178220
}
179221

222+
-(void) getPreference:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate {
223+
NSString* authId = command.arguments[0];
224+
NSString* key = command.arguments[1];
225+
NSString* result;
226+
NSError* getDefaultPreferenceError = nil;
227+
NSError* getSecuredPreferenceError = nil;
228+
229+
//Attempt fetching data
230+
OMPinAuthenticator* pinAuthenticator = [self getPinAuthenticator:authId];
231+
if (pinAuthenticator == nil) {
232+
OMDefaultAuthenticator *defAuth = [self getDefaultAuthenticator:DEFAULT_AUTH_ID];
233+
result = [defAuth.secureStorage dataForId:key error:&getDefaultPreferenceError];
234+
}
235+
else {
236+
result = [pinAuthenticator.secureStorage dataForId:key error:&getSecuredPreferenceError];
237+
if(result == nil) {
238+
OMDefaultAuthenticator *defAuth = [self getDefaultAuthenticator:DEFAULT_AUTH_ID];
239+
result = [defAuth.secureStorage dataForId:key error:&getDefaultPreferenceError];
240+
}
241+
}
242+
[commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:result] callbackId:command.callbackId];
243+
}
244+
245+
-(void) setPreference:(CDVInvokedUrlCommand*)command delegate:(CDVCommandDelegateImpl*) commandDelegate {
246+
NSString* authId = command.arguments[0];
247+
NSString* key = command.arguments[1];
248+
NSString* value = command.arguments[2];
249+
Boolean secure = [command.arguments[3] boolValue];
250+
NSError* setPreferenceError = nil;
251+
252+
if(!secure) {
253+
//Check if Default Authenticator is Enabled
254+
if(!self.defaultAuthenticationEnabled) {
255+
[commandDelegate sendPluginResult:[IdmAuthenticationPlugin errorCodeToPluginResult:ERROR_ENABLING_AUTHENTICATOR]
256+
callbackId:command.callbackId];
257+
}
258+
259+
//Attempt storing in default storage
260+
IdmLog(@"Storing in default storage");
261+
OMDefaultAuthenticator *defAuth = [self getDefaultAuthenticator:DEFAULT_AUTH_ID];
262+
if(value == nil)
263+
[defAuth.secureStorage deleteDataForId:key error:&setPreferenceError];
264+
else
265+
[defAuth.secureStorage saveDataForId:key data:value error:&setPreferenceError];
266+
267+
//Verify error and send result to plugin
268+
if(setPreferenceError) {
269+
[commandDelegate sendPluginResult:[IdmAuthenticationPlugin errorCodeToPluginResult:SAVING_VALUE_TO_DEFAULT_STORAGE_FAILED]
270+
callbackId:command.callbackId];
271+
}
272+
else {
273+
[commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Default Storage operation Successfull!!"] callbackId:command.callbackId];
274+
}
275+
276+
return;
277+
}
278+
//Check if PIN Authenticator is Enabled
279+
OMPinAuthenticator* pinAuthenticator = [self getPinAuthenticator:authId];
280+
if (pinAuthenticator == nil) {
281+
IdmLog(@"No enabled authenticators");
282+
[commandDelegate sendPluginResult:[IdmAuthenticationPlugin errorCodeToPluginResult:PIN_AUTHENTICATOR_NOT_ENABLED]
283+
callbackId:command.callbackId];
284+
return;
285+
}
286+
//Attempt storing in secured storage
287+
if (value == nil)
288+
[pinAuthenticator.secureStorage deleteDataForId:key error:&setPreferenceError];
289+
else
290+
[pinAuthenticator.secureStorage saveDataForId:key data:value error:&setPreferenceError];
291+
292+
//Verify error and send result to plugin
293+
if(setPreferenceError) {
294+
[commandDelegate sendPluginResult:[IdmAuthenticationPlugin errorCodeToPluginResult:SAVING_VALUE_TO_SECURED_STORAGE_FAILED]
295+
callbackId:command.callbackId];
296+
}
297+
else {
298+
[commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Secure Storage operation Successfull!!"] callbackId:command.callbackId];
299+
}
300+
}
301+
180302
-(void) authenticateBiometric:(CDVInvokedUrlCommand*)command
181303
delegate:(CDVCommandDelegateImpl*)commandDelegate {
182304
NSString* authId = command.arguments[0];
@@ -396,6 +518,8 @@ - (NSString *)authenticatorClassForType:(NSString*)authenticatorName
396518
return NSStringFromClass([OMBiometricAuthenticator class]);
397519
if ([LOCAL_AUTH_PIN isEqualToString:authenticatorName])
398520
return NSStringFromClass([OMPinAuthenticator class]);
521+
if ([LOCAL_AUTH_DEFAULT isEqualToString:authenticatorName])
522+
return NSStringFromClass([OMDefaultAuthenticator class]);
399523
return nil;
400524
}
401525

@@ -406,6 +530,8 @@ -(OMAuthenticator*) getAuthenticator:(NSString*) authId authenticatorName:(NSStr
406530
return [self getFingerprintAuthenticator:authId];
407531
else if ([LOCAL_AUTH_BIOMETRIC isEqualToString:authenticatorName])
408532
return [self getBiometricAuthenticator:authId];
533+
else if ([LOCAL_AUTH_DEFAULT isEqualToString:authenticatorName])
534+
return [self getDefaultAuthenticator:authId];
409535
return nil;
410536
}
411537

@@ -421,6 +547,18 @@ -(OMPinAuthenticator*) getPinAuthenticator:(NSString*) authId {
421547
return nil;
422548
}
423549

550+
-(OMDefaultAuthenticator*) getDefaultAuthenticator:(NSString*) authId {
551+
NSString* instanceId = [self getInstanceId:authId authenticatorName:LOCAL_AUTH_DEFAULT];
552+
if (![sharedManager isAuthenticatorRegistered:LOCAL_AUTH_DEFAULT])
553+
return nil;
554+
555+
OMAuthenticator* auth = [sharedManager authenticatorForInstanceId:instanceId error:nil];
556+
if (auth && [auth isKindOfClass:[OMDefaultAuthenticator class]]) {
557+
return (OMDefaultAuthenticator*) auth;
558+
}
559+
return nil;
560+
}
561+
424562
-(OMBiometricAuthenticator*) getFingerprintAuthenticator:(NSString*) authId {
425563
NSString* instanceId = [self getInstanceId:authId authenticatorName:LOCAL_AUTH_FINGERPRINT];
426564

tests/TestUtil.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ exports.defineAutoTests = function() {
304304
if (options.securedUrlResult)
305305
expect(results.securedUrlResult).toContain(options.securedUrlResult);
306306

307-
if (options.authHeader)
308-
expect(result.headers.Authorization).toBe(options.authHeader);
307+
if (options.authHeader) {
308+
expect(results.headers.Authorization).toBeDefined();
309+
expect(results.headers.ExpiryTime).toBeDefined();
310+
}
309311

310312
if (!options.noLogout)
311313
expect(results.authAfterLogout).not.toBeTruthy();

0 commit comments

Comments
 (0)