Skip to main content

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 ⏏

Kind: Exported class

new OAuthLoginDialog(options)

Throws:

  • Error if any of options.connector & options.url is missing.
ParamTypeDescription
optionsobject

Construction options holder

options.connectorConnector

AJAX transport. See Connector.

options.urlstring

Base URL of IDP

options.clientIdstring

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

ParamTypeDescription
accessTokenstring

The access token

expiresInnumber

Token expiration time in milliseconds.