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

Feature/Login Request Relay State #404

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
5 changes: 3 additions & 2 deletions src/binding-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ function buildRedirectURL(opts: BuildRedirectConfig) {
* @param {function} customTagReplacement used when developers have their own login response template
* @return {string} redirect URL
*/
function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacement?: (template: string) => BindingContext): BindingContext {
function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp, relayState?: string }, customTagReplacement?: (template: string) => BindingContext): BindingContext {

const metadata: any = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta };
const spSetting: any = entity.sp.entitySetting;
const relayState = entity.relayState ?? entity.sp.entitySetting.relayState;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be relayState ??= spSetting.relayState;? I'm not sure how this even builds currently because you have relayState parameter there and const variable with same name.

let id: string = '';

if (metadata && metadata.idp && metadata.sp) {
Expand Down Expand Up @@ -108,7 +109,7 @@ function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacem
isSigned: metadata.sp.isAuthnRequestSigned(),
entitySetting: spSetting,
baseUrl: base,
relayState: spSetting.relayState,
relayState,
}),
};
}
Expand Down
7 changes: 4 additions & 3 deletions src/entity-sp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export class ServiceProvider extends Entity {
*/
public createLoginRequest(
idp: IdentityProvider,
binding = 'redirect',
binding: 'redirect' | 'post' = 'redirect',
relayState?: string,
customTagReplacement?: (template: string) => BindingContext,
): BindingContext | PostBindingContext {
const nsBinding = namespace.binding;
Expand All @@ -64,14 +65,14 @@ export class ServiceProvider extends Entity {
}

if (protocol === nsBinding.redirect) {
return redirectBinding.loginRequestRedirectURL({ idp, sp: this }, customTagReplacement);
return redirectBinding.loginRequestRedirectURL({ idp, sp: this, relayState }, customTagReplacement);
}

if (protocol === nsBinding.post) {
const context = postBinding.base64LoginRequest("/*[local-name(.)='AuthnRequest']", { idp, sp: this }, customTagReplacement);
return {
...context,
relayState: this.entitySetting.relayState,
relayState: relayState ?? this.entitySetting.relayState,
entityEndpoint: idp.entityMeta.getSingleSignOnService(binding) as string,
type: 'SAMLRequest',
};
Expand Down