All files / src/oauth authorization-response.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                      221x         56x 56x 140x 139x     56x 56x    
/**
 * Authorization response redirects
 *
 * Every response from the authorization endpoint to the client's redirect URI, success or
 * error, carries `iss` so the client can tell which server answered (RFC 9207 section 2).
 */
 
/**
 * Build the redirect to a client's redirect URI with the given response parameters plus
 * `iss`. Empty or undefined values are omitted (an absent client `state` stays absent).
 */
export function authorizationRedirect(
  redirectUri: string,
  issuer: string,
  params: Record<string, string | undefined>,
): string {
  const url = new URL(redirectUri);
  for (const [name, value] of Object.entries(params)) {
    if (value) {
      url.searchParams.set(name, value);
    }
  }
  url.searchParams.set('iss', issuer);
  return url.toString();
}