-
Notifications
You must be signed in to change notification settings - Fork 3
Added on-prem IDM Deployment type #21
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
10d8ec8
842addf
c756f58
706ffc6
de6b8e5
b0ff7e5
f214452
c6dda67
cb11e18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { createHash, randomBytes } from 'crypto'; | |
| import url from 'url'; | ||
| import { v4 } from 'uuid'; | ||
|
|
||
| import { step } from '../api/AuthenticateApi'; | ||
| import { step, stepIdm } from '../api/AuthenticateApi'; | ||
| import { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi'; | ||
| import Constants from '../shared/Constants'; | ||
| import { State } from '../shared/State'; | ||
|
|
@@ -335,6 +335,7 @@ async function determineDeploymentType(state: State): Promise<string> { | |
| return deploymentType; | ||
|
|
||
| case Constants.CLASSIC_DEPLOYMENT_TYPE_KEY: | ||
| case Constants.IDM_DEPLOYMENT_TYPE_KEY: | ||
phalestrivir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| debugMessage({ | ||
| message: `AuthenticateOps.determineDeploymentType: end [type=${deploymentType}]`, | ||
| state, | ||
|
|
@@ -377,7 +378,7 @@ async function determineDeploymentType(state: State): Promise<string> { | |
| state, | ||
| }); | ||
| } catch (e) { | ||
| // debugMessage(e.response); | ||
| // If error is in that condition after sending Authorize | ||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ( | ||
| e.response?.status === 302 && | ||
| e.response.headers?.location?.indexOf('code=') > -1 | ||
|
|
@@ -409,10 +410,41 @@ async function determineDeploymentType(state: State): Promise<string> { | |
| }); | ||
| deploymentType = Constants.FORGEOPS_DEPLOYMENT_TYPE_KEY; | ||
| } else { | ||
| verboseMessage({ | ||
| message: `Classic deployment`['brightCyan'] + ` detected.`, | ||
| state, | ||
| }); | ||
| try { | ||
| //I need to check if it is idm here | ||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const idmresponse = await stepIdm({ | ||
|
||
| body: {}, | ||
| config: {}, | ||
| state, | ||
| }); | ||
| verboseMessage({ | ||
| message: `idm response = ${JSON.stringify(idmresponse.status, null, 2)} + ${idmresponse.data.authorization.authLogin}`, | ||
| state, | ||
| }); | ||
| if ( | ||
| idmresponse.status === 200 && | ||
| idmresponse.data?.authorization.authLogin | ||
| ) { | ||
| verboseMessage({ | ||
| message: | ||
| `Ping Identity IDM deployment`['brightCyan'] + | ||
| ` detected.`, | ||
| state, | ||
| }); | ||
| deploymentType = Constants.IDM_DEPLOYMENT_TYPE_KEY; | ||
| verboseMessage({ | ||
| message: 'deployment type in determine =' + deploymentType, | ||
| state, | ||
| }); | ||
| } else { | ||
| throw new Error('Not IDM'); | ||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } catch { | ||
|
||
| verboseMessage({ | ||
| message: `Classic deployment`['brightCyan'] + ` detected.`, | ||
| state, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -421,6 +453,7 @@ async function determineDeploymentType(state: State): Promise<string> { | |
| message: `AuthenticateOps.determineDeploymentType: end [type=${deploymentType}]`, | ||
| state, | ||
| }); | ||
|
|
||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return deploymentType; | ||
| } | ||
| } | ||
|
|
@@ -1049,7 +1082,6 @@ export type Tokens = { | |
| host?: string; | ||
| realm?: string; | ||
| }; | ||
|
|
||
phalestrivir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Get tokens | ||
| * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false) | ||
|
|
@@ -1098,14 +1130,13 @@ export async function getTokens({ | |
| ); | ||
| } | ||
| } | ||
|
|
||
| // if host is not a valid URL, try to locate a valid URL and deployment type from connections.json | ||
phalestrivir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!isValidUrl(state.getHost())) { | ||
| const conn = await getConnectionProfile({ state }); | ||
| state.setHost(conn.tenant); | ||
| state.setAllowInsecureConnection(conn.allowInsecureConnection); | ||
| state.setDeploymentType(conn.deploymentType); | ||
|
|
||
phalestrivir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // fail fast if deployment type not applicable | ||
| if ( | ||
| state.getDeploymentType() && | ||
|
|
@@ -1116,10 +1147,14 @@ export async function getTokens({ | |
| ); | ||
| } | ||
| } | ||
|
|
||
| // now that we have the full tenant URL we can lookup the cookie name | ||
| state.setCookieName(await determineCookieName(state)); | ||
|
|
||
| if (state.getHost().endsWith('openidm')) { | ||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| state.setDeploymentType(await determineDeploymentType(state)); | ||
| } | ||
| //check if it is idm deployment type, then it will just do some stuff for idm and break | ||
| else { | ||
| // now that we have the full tenant URL we can lookup the cookie name | ||
| state.setCookieName(await determineCookieName(state)); | ||
| } | ||
| // use service account to login? | ||
| if ( | ||
| !forceLoginAsUser && | ||
|
|
@@ -1160,31 +1195,43 @@ export async function getTokens({ | |
| message: `AuthenticateOps.getTokens: Authenticating with user account ${state.getUsername()}`, | ||
| state, | ||
| }); | ||
| const token = await getUserSessionToken(callbackHandler, state); | ||
| if (token) state.setUserSessionTokenMeta(token); | ||
| if (usingConnectionProfile && !token.from_cache) { | ||
| // if logging into on prem idm | ||
| if (state.getDeploymentType() === Constants.IDM_DEPLOYMENT_TYPE_KEY) { | ||
| const token: Tokens = { | ||
| subject: state.getUsername(), | ||
| host: state.getHost(), | ||
| realm: state.getRealm() ? state.getRealm() : 'root', | ||
| }; | ||
| saveConnectionProfile({ host: state.getHost(), state }); | ||
| } | ||
| await determineDeploymentTypeAndDefaultRealmAndVersion(state); | ||
| return token; | ||
phalestrivir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| const token = await getUserSessionToken(callbackHandler, state); | ||
| if (token) state.setUserSessionTokenMeta(token); | ||
| if (usingConnectionProfile && !token.from_cache) { | ||
| saveConnectionProfile({ host: state.getHost(), state }); | ||
| } | ||
| await determineDeploymentTypeAndDefaultRealmAndVersion(state); | ||
|
|
||
| // fail if deployment type not applicable | ||
| if ( | ||
| state.getDeploymentType() && | ||
| !types.includes(state.getDeploymentType()) | ||
| ) { | ||
| throw new FrodoError( | ||
| `Unsupported deployment type '${state.getDeploymentType()}'` | ||
| ); | ||
| } | ||
| // fail if deployment type not applicable | ||
| if ( | ||
| state.getDeploymentType() && | ||
| !types.includes(state.getDeploymentType()) | ||
| ) { | ||
| throw new FrodoError( | ||
| `Unsupported deployment type '${state.getDeploymentType()}'` | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| state.getCookieValue() && | ||
| // !state.getBearerToken() && | ||
| (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || | ||
| state.getDeploymentType() === Constants.FORGEOPS_DEPLOYMENT_TYPE_KEY) | ||
| ) { | ||
| const accessToken = await getUserBearerToken(state); | ||
| if (accessToken) state.setBearerTokenMeta(accessToken); | ||
| if ( | ||
| state.getCookieValue() && | ||
| // !state.getBearerToken() && | ||
| (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || | ||
| state.getDeploymentType() === | ||
| Constants.FORGEOPS_DEPLOYMENT_TYPE_KEY) | ||
| ) { | ||
| const accessToken = await getUserBearerToken(state); | ||
| if (accessToken) state.setBearerTokenMeta(accessToken); | ||
| } | ||
| } | ||
| } | ||
| // incomplete or no credentials | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I prefer consistency, but in this case I don't think the function name stepIdm makes sense. I think something like loginIdm or authenticateIdm would make more sense since IDM authentication doesn't have multiple steps like AM. Did I miss something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the reason he named it that is because there is a
stepfunction that does the usual AM authentication calls, so he called this onestepIdmsince it is for IDM authentication which is why I didn't think too much of it. However, I agree thatstepIdmis not the best name for it, since the reason the AM one is calledstepis because it is stepping through a journey to authenticate the Admin user when we create connection profiles. For IDM, we don't have steps to authenticate, it's just part of any request that is made to IDM to include the username/password to authenticate, so this would be a good change for you to make @skootrivir, assuming we can't find a better alternative to determine if the deployment is an IDM deployment as mentioned in the next comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will re-name this to 'authenticateIdm'