oauth.login.dialog
OAuthLoginDialog : d2/sdk/utils/oauth.login.dialog
Authenticate with an external IDP using OAuth2 and acquire access token. Requires popup to be enabled in browser.
Extends: Object
Example (A sample authentication with OTDS could look like)
define([
'd2/sdk/utils/contexts/context.utils',
'd2/sdk/utils/contexts/factories/connector'
'd2/sdk/utils/oauth.login.dialog'
], function(contextUtil, ConnectorFactory, OAuthLoginDialog){
'use strict';
var dlg = new OAuthLoginDialog({
connector: contextUtil.getPerspectiveContext().getObject(ConnectorFactory),
url: 'https://<OTDS_SERVER_IP>:8443/otdsws/oauth2/auth',
clientId: 'sample_system',
strings: {
title: 'Sign in to Sample System', //could be localized using i18n
authError: 'Authentication failed for Sample System' //could be localized using i18n
}
});
dlg
.login()
.then(function(accessToken, expiresIn){
console.log('Acquired token:' + accessToken + ' that is valid for ' + expiresIn + ' ms.'); //Even though console logging sensitive data is a bad idea, but it's always handy for a code snippet :-)
})
.catch(function(){
console.log('Auth failed');
});
});
- OAuthLoginDialog :
d2/sdk/utils/oauth.login.dialog
- OAuthLoginDialog ⏏
- new OAuthLoginDialog(options)
- instance
- .login() ⇒
jQyery.Promise
- .login() ⇒
- inner
- ~OAuthLoginSuccessCallback :
function
- ~OAuthLoginSuccessCallback :
- OAuthLoginDialog ⏏
OAuthLoginDialog ⏏
Kind: Exported class
new OAuthLoginDialog(options)
Throws:
- Error if any of
options.connector
&options.url
is missing.
Param | Type | Description |
---|---|---|
options | object | Construction options holder |
options.connector | Connector | AJAX transport. See Connector. |
options.url | string | Base URL of IDP |
options.clientId | string | Client ID of the system for which token is being requested. |
[options.strings] | Object.<string, string> | To control different displayable labels associated with the dialog. |
[options.strings.title] | string | Login dialog's title. |
[options.strings.message] | string | Login dialog's message. |
[options.strings.cancelBtn] | string | Login dialog's Cancel button label. |
[options.strings.authError] | string | Message to be shown if authentication fails. |
[options.strings.popupTitle] | string | Alert dialog's title if popup is diabled. |
[options.strings.popupWarning] | string | Alert dialog's message if popup is diabled. |
oAuthLoginDialog.login() ⇒ jQyery.Promise
Perform login to the external IDP. It checks existence of a valid access token first, if not found then login screen is shown.
Kind: instance method of OAuthLoginDialog
Returns: jQyery.Promise
- resolves and invokes OAuthLoginSuccessCallback
on successful login, rejects otherwise
OAuthLoginDialog~OAuthLoginSuccessCallback : function
Kind: inner typedef of OAuthLoginDialog
Param | Type | Description |
---|---|---|
accessToken | string | The access token |
expiresIn | number | Token expiration time in milliseconds. |