Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add idp parameter #46

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add optional idp parameter to sign in methods
dariusbakunas committed Sep 24, 2020
commit fe7732ff54dd2863c41c74cb41daec5d614f4b85
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -95,6 +95,8 @@ class AppID {
/**
* This will open a sign in widget in a popup which will prompt the user to enter their credentials.
* After a successful sign in, the popup will close and tokens are returned.
* @param {Object} options
* @param {string} options.idp - An enabled IdP name or "appid_anon" for anonymous login. If left empty, idp parameter that was set during initialization will be used
* @returns {Promise<Tokens>} The tokens of the authenticated user.
* @throws {PopupError} "Popup closed" - The user closed the popup before authentication was completed.
* @throws {TokenError} Any token validation error.
@@ -103,7 +105,7 @@ class AppID {
* @example
* const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin();
*/
async signin() {
async signin({ idp } = {}) {
this._validateInitalize();
const endpoint = this.openIdConfigResource.getAuthorizationEndpoint();
let origin = this.window.location.origin;
@@ -114,7 +116,7 @@ class AppID {
origin,
endpoint,
clientId: this.clientId,
idp: this.idp,
idp: idp || this.idp,
});
}

@@ -123,6 +125,8 @@ class AppID {
* This will attempt to authenticate the user in a hidden iframe.
* You will need to [enable Cloud Directory SSO]{@link https://cloud.ibm.com/docs/services/appid?topic=appid-single-page#spa-silent-login}.
* Sign in will be successful only if the user has previously signed in using Cloud Directory and their session is not expired.
* @param {Object} options
* @param {string} options.idp - An enabled IdP name or "appid_anon" for anonymous login. If left empty, idp parameter that was set during initialization will be used
* @returns {Promise<Tokens>} The tokens of the authenticated user.
* @throws {OAuthError} Any errors from the server according to the [OAuth spec]{@link https://tools.ietf.org/html/rfc6749#section-4.1.2.1}. e.g. {error: 'access_denied', description: 'User not signed in'}
* @throws {IFrameError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed.
@@ -131,15 +135,15 @@ class AppID {
* @example
* const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin();
*/
async silentSignin() {
async silentSignin({ idp } = {}) {
this._validateInitalize();
const endpoint = this.openIdConfigResource.getAuthorizationEndpoint();
const {codeVerifier, nonce, state, url} = this.utils.getAuthParamsAndUrl({
clientId: this.clientId,
origin: this.window.origin,
prompt: constants.PROMPT,
endpoint,
idp: this.idp,
idp: idp || this.idp,
});

this.iframe.open(url);