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

Stabilize OpenID Connect API integration tests. #173856

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion x-pack/plugins/security/server/routes/authentication/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n';
import type { RouteDefinitionParams } from '..';
import { OIDCAuthenticationProvider, OIDCLogin } from '../../authentication';
import type { ProviderLoginAttempt } from '../../authentication/providers/oidc';
import { wrapIntoCustomErrorResponse } from '../../errors';
import { getDetailedErrorMessage, wrapIntoCustomErrorResponse } from '../../errors';
import { createLicensedRouteHandler } from '../licensed_route_handler';
import { ROUTE_TAG_AUTH_FLOW, ROUTE_TAG_CAN_REDIRECT } from '../tags';

Expand Down Expand Up @@ -271,6 +271,7 @@ export function defineOIDCRoutes({

return response.unauthorized({ body: authenticationResult.error });
} catch (error) {
logger.error(`Failed to perform OIDC login: ${getDetailedErrorMessage(error)}`);
return response.customError(wrapIntoCustomErrorResponse(error));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* 2.0.
*/

import type { PluginInitializer, Plugin } from '@kbn/core/server';
import { PluginInitializer, Plugin, CoreSetup } from '@kbn/core/server';
import { initRoutes } from './init_routes';

export const plugin: PluginInitializer<void, void> = async (): Promise<Plugin> => ({
setup: (core) => initRoutes(core.http.createRouter()),
export const plugin: PluginInitializer<void, void> = async (
initializerContext
): Promise<Plugin> => ({
setup: (core: CoreSetup) => initRoutes(initializerContext, core),
start: () => {},
stop: () => {},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

import { schema } from '@kbn/config-schema';
import type { IRouter } from '@kbn/core/server';
import { CoreSetup, PluginInitializerContext } from '@kbn/core/server';
import { createTokens } from '@kbn/security-api-integration-helpers/oidc/oidc_tools';

export function initRoutes(router: IRouter) {
export function initRoutes(initializerContext: PluginInitializerContext, core: CoreSetup) {
const logger = initializerContext.logger.get();
const router = core.http.createRouter();

let nonce = '';
router.get(
{
Expand Down Expand Up @@ -69,17 +72,26 @@ export function initRoutes(router: IRouter) {
options: { authRequired: false, xsrfRequired: false },
},
(context, request, response) => {
const userId = request.body.code.substring(4);
const { accessToken, idToken } = createTokens(userId, nonce);
return response.ok({
body: {
access_token: accessToken,
token_type: 'Bearer',
refresh_token: `valid-refresh-token${userId}`,
expires_in: 3600,
id_token: idToken,
},
});
try {
const userId = request.body.code.substring(4);
logger.info(
`Accessing token endpoint for user ${userId} (headers: ${JSON.stringify(request.headers)}`
);

const { accessToken, idToken } = createTokens(userId, nonce);
return response.ok({
body: {
access_token: accessToken,
token_type: 'Bearer',
refresh_token: `valid-refresh-token${userId}`,
expires_in: 3600,
id_token: idToken,
},
});
} catch (err) {
logger.error(`Failed to create tokens: ${err?.message ?? err}`, err);
throw err;
}
}
);

Expand Down