Skip to content

Commit ee6157d

Browse files
committed
Changes for v1.6.0
1 parent 4f62dc4 commit ee6157d

File tree

8 files changed

+163
-8
lines changed

8 files changed

+163
-8
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.5.1
1+
# cordova-plugin-oracle-idm-auth 1.6.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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release Notes
22

3+
## 1.6.0 (23 Oct, 2020)
4+
* Support for two legged flow - FedAuth followed by a Basic Auth with native prompt.
5+
36
## 1.5.1 (25 May, 2020)
47
* Support for parsing password as character array.
58

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.5.1",
3+
"version": "1.6.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",

plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
77
xmlns:android="http://schemas.android.com/apk/res/android"
88
id="cordova-plugin-oracle-idm-auth"
9-
version="1.5.1">
9+
version="1.6.0">
1010
<name>cordova-plugin-oracle-idm-auth</name>
1111
<description>Provides authentication and authorization functionality using the Oracle IDM SDK, supporting standard protocols like Basic Auth, OAUTH, OpenID Connect and WebSSO</description>
1212
<keywords>cordova,idm,authentication,auth</keywords>
@@ -59,6 +59,7 @@
5959
<resource-file src="src/android/res/layout/activity_web_view.xml" target="res/layout/activity_web_view.xml"/>
6060
<resource-file src="src/android/res/layout/fingerprint_dialog_content.xml" target="res/layout/fingerprint_dialog_content.xml"/>
6161
<resource-file src="src/android/res/layout/fingerprint_dialog_container.xml" target="res/layout/fingerprint_dialog_container.xml"/>
62+
<resource-file src="src/android/res/layout/login_dialog.xml" target="res/layout/login_dialog.xml"/>
6263
<resource-file src="src/android/res/values/colors.xml" target="res/values/colors.xml"/>
6364
<resource-file src="src/android/res/values/cordova-plugin-oracle-idm-auth_strings.xml" target="res/values/cordova-plugin-oracle-idm-auth_strings.xml"/>
6465
<resource-file src="src/android/res/drawable/ic_fingerprint_error.xml" target="res/drawable/ic_fingerprint_error.xml"/>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:padding="20dp"
7+
android:paddingStart="20dp"
8+
android:paddingLeft="20dp"
9+
android:paddingTop="20dp"
10+
android:paddingEnd="20dp"
11+
android:paddingRight="20dp"
12+
android:paddingBottom="20dp">
13+
14+
<TextView
15+
android:id="@+id/textView"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:text="Username" />
19+
20+
<EditText
21+
android:id="@+id/httpAuthUsername"
22+
android:layout_width="341dp"
23+
android:layout_height="wrap_content"
24+
android:ems="10"
25+
android:inputType="textPersonName" />
26+
27+
<TextView
28+
android:id="@+id/textView2"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:paddingTop="10dp"
32+
android:text="Password" />
33+
34+
<EditText
35+
android:id="@+id/httpAuthPassword"
36+
android:layout_width="341dp"
37+
android:layout_height="wrap_content"
38+
android:ems="10"
39+
android:inputType="textPassword" />
40+
41+
</LinearLayout>

src/android/src/oracle/idm/auth/plugin/IdmAuthentication.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,15 @@ public CHALLENGE_TYPE getChallengeType()
415415
fields.put(_CHALLENGE_ERROR, IdmAuthenticationPlugin.errorToMap(errorCode));
416416
}
417417

418-
_loginCallback.success(new JSONObject(fieldsMap));
418+
if(fields.containsKey("http_auth_host_key")) {
419+
_mainActivity.runOnUiThread(() -> {
420+
_localBroadcastManager.sendBroadcast(new Intent(WebViewActivity.DISPLAY_LOGIN_DIALOG));
421+
});
422+
}
423+
else {
424+
_loginCallback.success(new JSONObject(fieldsMap));
425+
}
426+
419427
break;
420428
case EMBEDDED_WEBVIEW_REQUIRED:
421429
Log.d(TAG, "Handling embedded webview challenge.");

src/android/src/oracle/idm/auth/plugin/WebViewActivity.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import java.util.List;
1111
import java.util.Map;
1212

13+
import android.app.AlertDialog;
14+
import android.content.DialogInterface;
1315
import android.support.v4.content.LocalBroadcastManager;
1416
import android.util.Log;
1517
import android.view.View;
1618
import android.widget.Button;
19+
import android.widget.EditText;
1720
import android.widget.LinearLayout;
1821
import oracle.idm.auth.plugin.util.ResourceHelper;
1922
import oracle.idm.mobile.OMSecurityConstants;
@@ -35,6 +38,7 @@ public class WebViewActivity extends Activity
3538
public static final String FINISH_WEB_VIEW_INTENT = "finishWebView";
3639
public static final String CANCEL_WEB_VIEW_INTENT = "cancelFromWebView";
3740
public static final String BUTTONS_WEB_VIEW_PROP = "buttonsAvailable";
41+
public static final String DISPLAY_LOGIN_DIALOG = "displayLoginDialog";
3842

3943
@Override
4044
protected void onCreate(Bundle savedInstanceState)
@@ -60,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState)
6064
_broadcastReceiver = _createBroadcastReceiver();
6165
_localBroadcastManager = LocalBroadcastManager.getInstance(this);
6266
_localBroadcastManager.registerReceiver(_broadcastReceiver, new IntentFilter(FINISH_WEB_VIEW_INTENT));
67+
_localBroadcastManager.registerReceiver(_broadcastReceiver, new IntentFilter(DISPLAY_LOGIN_DIALOG));
6368

6469
_proceed(completionHandler);
6570
Log.d(TAG, "Created webview activity and passed on to IDM SDK.");
@@ -81,6 +86,42 @@ private void _proceed(IdmAuthentication.CompletionHandler completionHandler)
8186
completionHandler.proceed(responseFields);
8287
}
8388

89+
private void _showLoginDialog()
90+
{
91+
Log.d(TAG, "Displaying Login Dialog.");
92+
IdmAuthentication.CompletionHandler completionHandler = IdmAuthentication.getCompletionHandler();
93+
final AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
94+
95+
builder.setTitle("Please provide credentials").setCancelable(false)
96+
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
97+
@Override
98+
public void onClick(DialogInterface dialog, int which) {
99+
EditText usernameField = (EditText) _authView.findViewById(_R.getIdentifier(_HTTP_AUTH_USERNAME));
100+
EditText passwordField = (EditText) _authView.findViewById(_R.getIdentifier(_HTTP_AUTH_PASSWORD));
101+
String username = usernameField.getText().toString();
102+
char[] password = new char[passwordField.getText().length()];
103+
passwordField.getText().getChars(0, password.length, password, 0);
104+
105+
Map<String, Object> outParams = new HashMap<>();
106+
outParams.put(OMSecurityConstants.Challenge.USERNAME_KEY, username);
107+
outParams.put(OMSecurityConstants.Challenge.PASSWORD_KEY_2, password);
108+
completionHandler.proceed(outParams);
109+
110+
}
111+
})
112+
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
113+
@Override
114+
public void onClick(DialogInterface dialog, int which) {
115+
completionHandler.cancel();
116+
}
117+
});
118+
119+
AlertDialog alertDialog = builder.create();
120+
_authView = alertDialog.getLayoutInflater().inflate(_R.getLayout("login_dialog"), null);
121+
alertDialog.setView(_authView);
122+
alertDialog.show();
123+
}
124+
84125
private BroadcastReceiver _createBroadcastReceiver()
85126
{
86127
return new BroadcastReceiver()
@@ -95,6 +136,10 @@ public void onReceive(Context context, Intent intent)
95136
_webView.destroy();
96137
finish();
97138
}
139+
else if (DISPLAY_LOGIN_DIALOG.equals(action))
140+
{
141+
_showLoginDialog();
142+
}
98143
}
99144
};
100145
}
@@ -221,9 +266,11 @@ public void onClick(View v)
221266
private WebViewClient _webViewClient;
222267
private BroadcastReceiver _broadcastReceiver;
223268
private LocalBroadcastManager _localBroadcastManager;
269+
private View _authView;
224270

225271
private static final String TAG = WebViewActivity.class.getSimpleName();
226272
private static final ResourceHelper _R = ResourceHelper.INSTANCE;
273+
private static final String _LOGIN_DIALOG_LAYOUT = "login_dialog";
227274
private static final String _ACTIVITY_WEB_VIEW = "activity_web_view";
228275
private static final String _IDM_WEB_VIEW = "idmWebView";
229276
private static final String _BTN_LAYOUT = "button_layout";
@@ -237,4 +284,6 @@ public void onClick(View v)
237284
private static final String _BACK_BTN_FLAG = "BACK";
238285
private static final String _ALL_BTN_FLAG = "ALL";
239286
private static final String _NO_BTN_FLAG = "NONE";
287+
private static final String _HTTP_AUTH_USERNAME = "httpAuthUsername";
288+
private static final String _HTTP_AUTH_PASSWORD = "httpAuthPassword";
240289
}

src/ios/src/IdmAuthentication.m

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#define AUTH_WEB_VIEW @"AuthWebView"
2525
#define CHALLENGE_ERROR @"error"
2626
#define PROP_ENABLE_WEB_VIEW_BUTTONS @"EnableWebViewButtons"
27+
#define LOGIN_DIALOG_TITLE @"Please provide credentials"
28+
#define USERNAME_PLACEHOLDER @"Enter Username"
29+
#define PASSWORD_PLACEHOLDER @"Enter Password"
2730

2831

2932
#ifdef DEBUG
@@ -385,6 +388,50 @@ -(void) mobileSecurityService:(OMMobileSecurityService *)mss
385388
self.setupCompletionCallback(self, error);
386389
IdmLog(@"completedSetupWithConfiguration done with Error %@", error);
387390
}
391+
392+
/**
393+
* Method to show login dialog.
394+
*/
395+
- (void) showLoginDialog: (NSDictionary*) fields{
396+
UIAlertController* loginAlert = [UIAlertController alertControllerWithTitle:LOGIN_DIALOG_TITLE message:nil preferredStyle:UIAlertControllerStyleAlert];
397+
398+
[loginAlert addTextFieldWithConfigurationHandler:^(UITextField* usernameField) {
399+
usernameField.placeholder = USERNAME_PLACEHOLDER;
400+
usernameField.clearButtonMode = UITextFieldViewModeWhileEditing;
401+
usernameField.borderStyle = UITextBorderStyleRoundedRect;
402+
}];
403+
404+
[loginAlert addTextFieldWithConfigurationHandler:^(UITextField* passwordField) {
405+
passwordField.placeholder = PASSWORD_PLACEHOLDER;
406+
passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
407+
passwordField.borderStyle = UITextBorderStyleRoundedRect;
408+
passwordField.secureTextEntry = YES;
409+
}];
410+
411+
412+
UIAlertAction* submitAction = [UIAlertAction actionWithTitle: @ "Submit"
413+
style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _Nonnull action) {
414+
415+
[fields setValue:loginAlert.textFields[0].text forKey:OM_USERNAME];
416+
[fields setValue:loginAlert.textFields[1].text forKey:OM_PASSWORD];
417+
418+
self.challenge.authChallengeHandler(fields, OMProceed);
419+
NSLog(@ "Submit Tapped");
420+
}];
421+
422+
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle: @ "Cancel"
423+
style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _Nonnull action) {
424+
[self dismissAuthView];
425+
self.challenge.authChallengeHandler(nil, OMCancel);
426+
NSLog(@ "Cancel Tapped");
427+
}];
428+
429+
[loginAlert addAction: submitAction];
430+
[loginAlert addAction: cancelAction];
431+
432+
[self.authViewController presentViewController:loginAlert animated: true completion: nil];
433+
}
434+
388435
/**
389436
* OMMobileSecurityServiceDelegate protocol implementation
390437
*/
@@ -401,10 +448,16 @@ -(void) mobileSecurityService:(OMMobileSecurityService *)mss
401448
}
402449

403450
if (challenge.challengeType == OMChallengeUsernamePassword) {
404-
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"challengeFields": fields}];
405-
[self.loginLogoutCommandDelegate sendPluginResult:result callbackId:self.loginLogoutCallbackId];
406-
IdmLog(@"Sending challenge back to user to fill up.");
407-
return;
451+
if([fields objectForKey:@"webview_key"]) {
452+
[self showLoginDialog:fields];
453+
}
454+
else {
455+
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"challengeFields": fields}];
456+
[self.loginLogoutCommandDelegate sendPluginResult:result callbackId:self.loginLogoutCallbackId];
457+
IdmLog(@"Sending challenge back to user to fill up.");
458+
459+
return;
460+
}
408461
} else if (challenge.challengeType == OMChallengeEmbeddedBrowser) {
409462
self.challenge = challenge;
410463
IdmLog(@"Launching webview and redirecting user to login web page.");

0 commit comments

Comments
 (0)