Skip to content

Commit

Permalink
Make sure hash is carried over when OIDC is only auth type for ODS
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Aug 25, 2023
1 parent 6672cdb commit b877019
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
35 changes: 23 additions & 12 deletions server/auth/types/openid/openid_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import {
LifecycleResponseFactory,
AuthToolkit,
IOpenSearchDashboardsResponse,
AuthResult,
} from 'opensearch-dashboards/server';
import HTTP from 'http';
import HTTPS from 'https';
import { PeerCertificate } from 'tls';
import { Server, ServerStateCookieOptions } from '@hapi/hapi';
import { SecurityPluginConfigType } from '../../..';
import { SecuritySessionCookie } from '../../../session/security_cookie';
import {
SecuritySessionCookie,
clearOldVersionCookieValue,
} from '../../../session/security_cookie';
import { OpenIdAuthRoutes } from './routes';
import { AuthenticationType } from '../authentication_type';
import { callTokenEndpoint } from './helper';
Expand Down Expand Up @@ -118,6 +122,22 @@ export class OpenIdAuthentication extends AuthenticationType {
}
}

private generateNextUrl(request: OpenSearchDashboardsRequest): string {
const path =
this.coreSetup.http.basePath.serverBasePath +
(request.url.pathname || '/app/opensearch-dashboards');
return escape(path);
}

private redirectOIDCCapture = (request: OpenSearchDashboardsRequest, toolkit: AuthToolkit) => {
const nextUrl = this.generateNextUrl(request);
const clearOldVersionCookie = clearOldVersionCookieValue(this.config);
return toolkit.redirected({
location: `${this.coreSetup.http.basePath.serverBasePath}/auth/openid/captureUrlFragment?nextUrl=${nextUrl}`,
'set-cookie': clearOldVersionCookie,
});
};

private createWreckClient(): typeof wreck {
const wreckHttpsOption: WreckHttpsOptions = {};
if (this.config.openid?.root_ca) {
Expand Down Expand Up @@ -266,18 +286,9 @@ export class OpenIdAuthentication extends AuthenticationType {
request: OpenSearchDashboardsRequest,
response: LifecycleResponseFactory,
toolkit: AuthToolkit
): IOpenSearchDashboardsResponse {
): IOpenSearchDashboardsResponse | AuthResult {
if (this.isPageRequest(request)) {
// nextUrl is a key value pair
const nextUrl = composeNextUrlQueryParam(
request,
this.coreSetup.http.basePath.serverBasePath
);
return response.redirected({
headers: {
location: `${this.coreSetup.http.basePath.serverBasePath}${OPENID_AUTH_LOGIN}?${nextUrl}`,
},
});
return this.redirectOIDCCapture(request, toolkit);
} else {
return response.unauthorized();
}
Expand Down
4 changes: 3 additions & 1 deletion server/auth/types/openid/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
OpenSearchDashboardsRequest,
Logger,
} from '../../../../../../src/core/server';
import { SecuritySessionCookie } from '../../../session/security_cookie';
import {

Check failure on line 27 in server/auth/types/openid/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Replace `⏎··SecuritySessionCookie,⏎` with `·SecuritySessionCookie·`

Check failure on line 27 in server/auth/types/openid/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Replace `⏎··SecuritySessionCookie,⏎` with `·SecuritySessionCookie·`
SecuritySessionCookie,
} from '../../../session/security_cookie';
import { SecurityPluginConfigType } from '../../..';
import { OpenIdAuthConfig } from './openid_auth';
import { SecurityClient } from '../../../backend/opensearch_security_client';
Expand Down

0 comments on commit b877019

Please sign in to comment.