Skip to content

Commit 604eacf

Browse files
committed
fix: make sure pro connected user return also the name
1 parent bf76378 commit 604eacf

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

api/src/core/usecases/auth/handleAuthCallback.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const makeHandleAuthCallback = ({
4444
sub: userInfoFromProvider.sub,
4545
email: userInfoFromProvider.email,
4646
firstName: userInfoFromProvider.given_name,
47-
lastName: userInfoFromProvider.family_name,
47+
lastName: userInfoFromProvider.family_name ?? userInfoFromProvider.usual_name,
4848
organization: null,
4949
isPublic: false,
5050
about: undefined
@@ -57,7 +57,7 @@ export const makeHandleAuthCallback = ({
5757
sub: userInfoFromProvider.sub,
5858
email: userInfoFromProvider.email,
5959
firstName: userInfoFromProvider.given_name,
60-
lastName: userInfoFromProvider.family_name
60+
lastName: userInfoFromProvider.family_name ?? userInfoFromProvider.usual_name
6161
});
6262
}
6363

api/src/core/usecases/auth/initiateAuth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const makeInitiateAuth = ({ sessionRepository, oidcClient }: InitiateAuth
3333
client_id: oidcClient.clientId,
3434
redirect_uri: oidcClient.redirectUri,
3535
state,
36-
scope: "openid email profile"
36+
scope: oidcClient.scope
3737
}).toString();
3838

3939
return { sessionId, authUrl: authUrl.toString() };

api/src/core/usecases/auth/oidcClient.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ type OidcUserInfo = {
2222
name?: string;
2323
given_name?: string;
2424
family_name?: string;
25+
// following is not standard, it is just for ProConnect
26+
usual_name?: string;
2527
};
2628

2729
export interface OidcClient {
2830
clientId: string;
2931
redirectUri: string;
32+
scope: string;
3033
getAuthorizationEndpoint(): string;
3134
exchangeCodeForTokens(code: string): Promise<{
3235
access_token: string;
@@ -39,12 +42,23 @@ export interface OidcClient {
3942
logout(idToken: string | null): Promise<string>;
4043
}
4144

45+
const standardOidcScope = ["openid", "email", "profile"];
46+
47+
const getScope = (oidcIssuerUri: string): string => {
48+
if (oidcIssuerUri.includes("agentconnect") || oidcIssuerUri.includes("proconnect"))
49+
return [...standardOidcScope, "given_name", "usual_name"].join(" ");
50+
return standardOidcScope.join(" ");
51+
};
52+
4253
export class HttpOidcClient implements OidcClient {
4354
#config!: OidcConfiguration;
4455
#oidcParams: OidcParams;
4556

57+
public scope: string;
58+
4659
private constructor(oidcParams: OidcParams) {
4760
this.#oidcParams = oidcParams;
61+
this.scope = getScope(oidcParams.issuerUri);
4862
}
4963

5064
static async create(oidcParams: OidcParams): Promise<HttpOidcClient> {
@@ -123,8 +137,6 @@ export class HttpOidcClient implements OidcClient {
123137

124138
const userInfoAsString = responseBody.startsWith("ey") ? atob(responseBody.split(".")[1]) : responseBody;
125139

126-
console.log("\n \n userInfoAsString : ", userInfoAsString);
127-
128140
return JSON.parse(userInfoAsString);
129141
}
130142

@@ -152,9 +164,11 @@ export class TestOidcClient implements OidcClient {
152164
#config: OidcConfiguration;
153165
#oidcParams: OidcParams;
154166
#calls: TestOidcClientCall[] = [];
167+
scope: string;
155168

156169
constructor(oidcParams: OidcParams) {
157170
this.#oidcParams = oidcParams;
171+
this.scope = getScope(oidcParams.issuerUri);
158172
this.#config = {
159173
authorization_endpoint: `${oidcParams.issuerUri}/auth`,
160174
token_endpoint: `${oidcParams.issuerUri}/token`,

0 commit comments

Comments
 (0)