Skip to content

Commit acdb474

Browse files
authored
chore: [SIW-2197] Make idphint parameter optional for auth request url (#212)
1 parent ec48645 commit acdb474

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎src/credential/issuance/04-complete-user-authorization.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type BuildAuthorizationUrl = (
4949
issuerRequestUri: Out<StartUserAuthorization>["issuerRequestUri"],
5050
clientId: Out<StartUserAuthorization>["clientId"],
5151
issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
52-
idpHint: string
52+
idpHint?: string
5353
) => Promise<{
5454
authUrl: string;
5555
}>;
@@ -60,7 +60,7 @@ export type BuildAuthorizationUrl = (
6060
* @param issuerRequestUri the URI of the issuer where the request is sent
6161
* @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
6262
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
63-
* @param idpHint Unique identifier of the IDP selected by the user
63+
* @param idpHint Unique identifier of the IDP selected by the user (optional)
6464
* @returns An object containing the authorization URL
6565
*/
6666
export const buildAuthorizationUrl: BuildAuthorizationUrl = async (
@@ -75,9 +75,12 @@ export const buildAuthorizationUrl: BuildAuthorizationUrl = async (
7575
const params = new URLSearchParams({
7676
client_id: clientId,
7777
request_uri: issuerRequestUri,
78-
idphint: idpHint,
7978
});
8079

80+
if (idpHint) {
81+
params.append("idphint", idpHint);
82+
}
83+
8184
const authUrl = `${authzRequestEndpoint}?${params}`;
8285

8386
return { authUrl };

‎src/credential/issuance/__tests__/04-complete-user-authorization.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { AuthorizationError, AuthorizationIdpError } from "../errors";
2-
import { completeUserAuthorizationWithQueryMode } from "../04-complete-user-authorization";
2+
import {
3+
buildAuthorizationUrl,
4+
completeUserAuthorizationWithQueryMode,
5+
} from "../04-complete-user-authorization";
6+
import type { Out } from "src/utils/misc";
7+
import type { EvaluateIssuerTrust } from "src/credential/status";
38

49
describe("authorizeUserWithQueryMode", () => {
510
it("should return the authorization result when the authorization server responds with a valid response", async () => {
@@ -45,3 +50,40 @@ describe("authorizeUserWithQueryMode", () => {
4550
}
4651
});
4752
});
53+
54+
describe("buildAuthorizationUrl", () => {
55+
it("should build the authorization URL", async () => {
56+
const authUrl = await buildAuthorizationUrl(
57+
"issuerRequestUri",
58+
"clientId",
59+
{
60+
oauth_authorization_server: {
61+
authorization_endpoint: "https://issuer.com/authorize",
62+
},
63+
} as Out<EvaluateIssuerTrust>["issuerConf"],
64+
"idpHint"
65+
);
66+
67+
expect(authUrl).toMatchObject({
68+
authUrl:
69+
"https://issuer.com/authorize?client_id=clientId&request_uri=issuerRequestUri&idphint=idpHint",
70+
});
71+
});
72+
73+
it("should build the authorization URL without idpHint", async () => {
74+
const authUrl = await buildAuthorizationUrl(
75+
"issuerRequestUri",
76+
"clientId",
77+
{
78+
oauth_authorization_server: {
79+
authorization_endpoint: "https://issuer.com/authorize",
80+
},
81+
} as Out<EvaluateIssuerTrust>["issuerConf"]
82+
);
83+
84+
expect(authUrl).toMatchObject({
85+
authUrl:
86+
"https://issuer.com/authorize?client_id=clientId&request_uri=issuerRequestUri",
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)