Merge pull request #18783 from cloudoutloud/docs/update-aws-alb-auth

Docs/update aws alb auth
This commit is contained in:
Fredrik Adelöw
2023-07-28 16:11:29 +02:00
committed by GitHub
+23 -16
View File
@@ -58,6 +58,7 @@ When using ALB authentication Backstage will only be loaded once the user has su
import React from 'react';
import { UserIdentity } from '@backstage/core-components';
import { SignInPageProps } from '@backstage/core-app-api';
import { useApi, configApiRef } from '@backstage/core-plugin-api';
const SampleSignInComponent: any = (props: SignInPageProps) => {
const [error, setError] = React.useState<string | undefined>();
@@ -90,8 +91,8 @@ const SampleSignInComponent: any = (props: SignInPageProps) => {
},
}),
);
} catch (err) {
setError(err.message);
} catch (err: any) {
setError(err.message as string);
}
}
}, [config]);
@@ -135,12 +136,14 @@ export default async function createPlugin({
database,
config,
discovery,
tokenManager,
}: PluginEnvironment): Promise<Router> {
return await createRouter({
logger,
config,
database,
discovery,
tokenManager,
providerFactories: {
awsalb: providers.awsAlb.create({
authHandler: async ({ fullProfile }) => {
@@ -168,25 +171,29 @@ export default async function createPlugin({
};
},
signIn: {
resolver: async ({ profile: { email } }, ctx) => {
const [id] = email?.split('@') ?? '';
// Fetch from an external system that returns entity claims like:
// ['user:default/breanna.davison', ...]
const userEntityRef = stringifyEntityRef({
resolver: async ({ profile }, ctx) => {
if (!profile.email) {
throw new Error('Profile contained no email');
}
const [id] = profile.email.split('@');
if (!id) {
throw new Error('Invalid email format');
}
const userRef = stringifyEntityRef({
kind: 'User',
namespace: DEFAULT_NAMESPACE,
name: id,
namespace: DEFAULT_NAMESPACE,
});
// Resolve group membership from the Backstage catalog
const fullEnt =
await ctx.catalogIdentityClient.resolveCatalogMembership({
entityRefs: [id].concat([userEntityRef]),
logger: ctx.logger,
});
const token = await ctx.tokenIssuer.issueToken({
claims: { sub: userEntityRef, ent: fullEnt },
const { token } = await ctx.issueToken({
claims: {
sub: userRef,
ent: [userRef],
},
});
return { id, token };
},
},