-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reworked options and injectables
BREAKING CHANGE: Structure and options
- Loading branch information
1 parent
bff0472
commit 3ecc9cb
Showing
11 changed files
with
393 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { | ||
BackstageSignInResult, | ||
BackstageIdentityResponse, | ||
LDAPUser, | ||
} from './types'; | ||
|
||
import { ProfileInfo } from '@backstage/core-plugin-api'; | ||
import { | ||
AuthHandler, | ||
AuthResolverContext, | ||
SignInResolver, | ||
} from '@backstage/plugin-auth-backend'; | ||
import { parseJwtPayload } from './jwt'; | ||
|
||
export function prepareBackstageIdentityResponse( | ||
result: BackstageSignInResult | ||
): BackstageIdentityResponse { | ||
const { sub, ent } = parseJwtPayload(result.token); | ||
|
||
return { | ||
...result, | ||
identity: { | ||
type: 'user', | ||
userEntityRef: sub, | ||
ownershipEntityRefs: ent ?? [], | ||
}, | ||
}; | ||
} | ||
|
||
export const defaultSigninResolver: SignInResolver<LDAPUser> = async ( | ||
{ result }, | ||
ctx: AuthResolverContext | ||
): Promise<BackstageSignInResult> => { | ||
const backstageIdentity: BackstageSignInResult = | ||
await ctx.signInWithCatalogUser({ | ||
entityRef: result.uid as string, | ||
}); | ||
|
||
return backstageIdentity; | ||
}; | ||
|
||
export const defaultAuthHandler: AuthHandler<LDAPUser> = async ( | ||
{ uid }, | ||
ctx: AuthResolverContext | ||
): Promise<{ profile: ProfileInfo }> => { | ||
const backstageUserData = await ctx.findCatalogUser({ | ||
entityRef: uid as string, | ||
}); | ||
return { profile: backstageUserData?.entity?.spec?.profile as ProfileInfo }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.