Skip to content

Commit

Permalink
get connect user siret and store it in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Jan 23, 2025
1 parent 906658b commit 6ddf47e
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion back/src/config/bootstrap/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class AppConfig {
? "https://fake-pro-connect.url"
: undefined,
),
scope: "openid given_name usual_name email custom",
scope: "openid given_name usual_name email custom siret",
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class HttpOAuthGateway implements OAuthGateway {
lastName: oAuthIdTokenPayload.usual_name,
email: oAuthIdTokenPayload.email,
structure_pe: oAuthIdTokenPayload.custom.structureTravail,
siret: oAuthIdTokenPayload.siret,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Email, ExternalId, emailSchema } from "shared";
import { Email, ExternalId, SiretDto, emailSchema, siretSchema } from "shared";
import { z } from "zod";

type ProviderTokenPayloadBase = {
Expand All @@ -15,6 +15,7 @@ export type IcOAuthIdTokenPayload = ProviderTokenPayloadBase & {

export type ProConnectOAuthIdTokenPayload = ProviderTokenPayloadBase & {
usual_name: string;
siret: SiretDto;
custom: {
structureTravail?: string;
};
Expand All @@ -39,4 +40,5 @@ export const proConnectAuthTokenPayloadSchema: z.Schema<ProConnectOAuthIdTokenPa
custom: z.object({
structureTravail: z.string().optional(),
}),
siret: siretSchema,
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type GetAccessTokenPayload = {
lastName: string;
email: Email;
structure_pe?: string;
siret?: string; // remove optional when inclusion connect is removed
};

export type GetAccessTokenResult = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export class AuthenticateWithInclusionCode extends TransactionalUseCase<
firstName: newOrUpdatedAuthenticatedUser.firstName,
lastName: newOrUpdatedAuthenticatedUser.lastName,
email: newOrUpdatedAuthenticatedUser.email,
siret: payload.siret,
idToken,
})}`;
}
Expand Down
6 changes: 6 additions & 0 deletions front/src/app/routes/InclusionConnectedPrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useAppSelector } from "src/app/hooks/reduxHooks";
import { FrontAdminRouteTab } from "src/app/pages/admin/AdminTabs";
import { routes } from "src/app/routes/routes";
import { loginIllustration } from "src/assets/img/illustrations";
import { outOfReduxDependencies } from "src/config/dependencies";
import { authSelectors } from "src/core-logic/domain/auth/auth.selectors";
import { authSlice } from "src/core-logic/domain/auth/auth.slice";
import { featureFlagSelectors } from "src/core-logic/domain/featureFlags/featureFlags.selector";
Expand Down Expand Up @@ -133,6 +134,7 @@ export const InclusionConnectedPrivateRoute = ({
firstName = "",
lastName = "",
idToken = "",
siret = "",
} = route.params;

if (token) {
Expand All @@ -149,6 +151,10 @@ export const InclusionConnectedPrivateRoute = ({
feedbackTopic: "auth-global",
}),
);
outOfReduxDependencies.localDeviceRepository.set(
"connectedUserSiret",
siret,
);
const { token: _, ...routeParams } = route.params;
routes[route.name](routeParams as any).replace();
}
Expand Down
1 change: 1 addition & 0 deletions front/src/app/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type AcquisitionParams = Partial<{
type AcquisitionParamsKeys = keyof typeof acquisitionParams;

const inclusionConnectedParams = createInclusionConnectedParams({
siret: param.query.optional.string,
page: param.query.optional.string,
token: param.query.optional.string,
firstName: param.query.optional.string,
Expand Down
1 change: 1 addition & 0 deletions front/src/core-logic/domain/auth/auth.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const deleteFederatedIdentityFromDevice: AuthEpic = (
action$.pipe(
filter(authSlice.actions.federatedIdentityDeletionTriggered.match),
tap(() => localDeviceRepository.delete("federatedIdentityWithUser")),
tap(() => localDeviceRepository.delete("connectedUserSiret")),
tap(() => localDeviceRepository.delete("partialConventionInUrl")),
map(() => authSlice.actions.federatedIdentityInDeviceDeletionSucceeded()),
);
Expand Down
3 changes: 2 additions & 1 deletion front/src/core-logic/ports/DeviceRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type LocalStoragePair =
| GenericPair<"partialConventionInUrl", Partial<ConventionParamsInUrl>>
| GenericPair<"adminToken", string>
| GenericPair<"federatedIdentityWithUser", FederatedIdentityWithUser>
| GenericPair<"searchResultExternal", SearchResultDto>;
| GenericPair<"searchResultExternal", SearchResultDto>
| GenericPair<"connectedUserSiret", string>;

export type SessionStoragePair =
| GenericPair<"acquisitionParams", WithAcquisition>
Expand Down
1 change: 1 addition & 0 deletions shared/src/inclusionConnect/inclusionConnect.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type WithSourcePage = {
export type AuthenticatedUserQueryParams = {
token: InclusionConnectJwt;
idToken: string;
siret?: string; // remove optional when inclusion connect is removed
} & Pick<User, "email" | "firstName" | "lastName">;

type InclusionConnectConventionManageAllowedRole =
Expand Down

0 comments on commit 6ddf47e

Please sign in to comment.