| @@ -0,0 +1,168 @@ | |||
| INSCRIPTION SUR AZURE-AD - SERVEUR DE TESTS | |||
| =========================================== | |||
| Nom application : GIEBOX-SSO-Proxiel | |||
| Id application (client) : 2bc71bd9-d762-456c-a4fb-8123281b337c | |||
| Id de l'annuaire : ee62f470-e454-4f4c-a3c4-ac4e1e9208af | |||
| Secret : | |||
| Temps validité : 24 mois | |||
| Valeur : 2ZH8Q~KOeFYK8o5k-tFiCBHOUhWJD2_zbdmbebDt | |||
| Id secret : f59cfdb0-ecc5-4f10-99d0-f191afb290e7 | |||
| Autorisation : SSO OAuth2 / OpenID Connect (OIDC) | |||
| URLs : | |||
| - https://giebox.proxiel.com/authentication/login-callback | |||
| - https://giebox.proxiel.com/authentication/logout-callback | |||
| INSCRIPTION SUR AZURE-AD - POSTE DE DEV | |||
| ======================================= | |||
| Nom application : GIEBOX-SSO-Proxiel-DEV | |||
| Id application (client) : bc191d1f-36b4-44ee-b6ab-ffed25ff5276 | |||
| Id de l'annuaire : ee62f470-e454-4f4c-a3c4-ac4e1e9208af | |||
| Id de l'objet : cb09c2b4-05ff-4a36-b877-abfb71633695 | |||
| Secret : | |||
| Temps validité : 24 mois | |||
| Valeur : Ep68Q~VSlnaks8~dVHbuUzgQ7oRxKVlmxj4V0drP | |||
| Id secret : 42d3ca95-cd48-4a3e-b42a-64099980e3f5 | |||
| Autorisation : SSO OAuth2 / OpenID Connect (OIDC) | |||
| URLs : | |||
| - https://localhost:7286/authentication/login-callback | |||
| - https://localhost:7286/authentication/logout-callback | |||
| Compte test Messagerie : | |||
| ======================== | |||
| Nom complet: Giebox Proxiel | |||
| Nom d’utilisateur: gieboxproxiel@giequalite.fr | |||
| Mot de passe: D^504762498695at | |||
| PRE-REQUIS | |||
| ========== | |||
| dotnet add package Microsoft.Authentication.WebAssembly.Msal | |||
| 1. appsettings.json | |||
| =================== | |||
| { | |||
| "AzureAd": { | |||
| "Authority": "https://login.microsoftonline.com/ee62f470-e454-zzzz-a3c4-ac4e1e9208af", --> ID ANNUAIRE | |||
| "ClientId": "2bc71bd9-zzzz-456c-a4fb-8123281b337c --> ID APPLICATION | |||
| "ValidateAuthority": true | |||
| } | |||
| } | |||
| 2. program.cs | |||
| ============= | |||
| // --- CONFIGURATION SSO AZURE AD --- | |||
| builder.Services.AddMsalAuthentication(options => | |||
| { | |||
| builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication); | |||
| // Optionnel : Scopes par défaut pour lire le profil utilisateur | |||
| options.ProviderOptions.DefaultAccessTokenScopes.Add("openid"); | |||
| options.ProviderOptions.DefaultAccessTokenScopes.Add("profile"); | |||
| }); | |||
| 3. index.html | |||
| ============= | |||
| <script src="_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js"></script> | |||
| 4. _Imports.razor | |||
| ================= | |||
| @using Microsoft.AspNetCore.Components.Authorization | |||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | |||
| 5. App.razor | |||
| ============ | |||
| <CascadingAuthenticationState> | |||
| <Router AppAssembly="@typeof(App).Assembly"> | |||
| <Found Context="routeData"> | |||
| <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> | |||
| <NotAuthorized> | |||
| @if (context.User.Identity?.IsAuthenticated != true) | |||
| { | |||
| <RedirectToLogin /> | |||
| } | |||
| else | |||
| { | |||
| <p role="alert">Désolé, vous n'avez pas accès à cette page.</p> | |||
| } | |||
| </NotAuthorized> | |||
| </AuthorizeRouteView> | |||
| <FocusOnNavigate RouteData="@routeData" Selector="h1" /> | |||
| </Found> | |||
| <NotFound> | |||
| <PageTitle>Introuvable</PageTitle> | |||
| <LayoutView Layout="@typeof(MainLayout)"> | |||
| <p role="alert">Désolé, il n'y a rien à cette adresse.</p> | |||
| </LayoutView> | |||
| </NotFound> | |||
| </Router> | |||
| </CascadingAuthenticationState> | |||
| 6. Shared/RedirectToLogin.razor | |||
| =============================== | |||
| @inject NavigationManager Navigation | |||
| @code { | |||
| protected override void OnInitialized() | |||
| { | |||
| // Redirige vers la route spéciale gérée par le script MSAL | |||
| Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); | |||
| } | |||
| } | |||
| 7. MainLayout.razor | |||
| =================== | |||
| @using Microsoft.AspNetCore.Components.Authorization | |||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | |||
| @inject NavigationManager Navigation | |||
| @inject SignOutSessionStateManager SignOutManager | |||
| <AuthorizeView> | |||
| <Authorized> | |||
| Hello, @context.User.Identity?.Name! | |||
| <button class="nav-link btn btn-link" @onclick="BeginLogOut">Déconnexion</button> | |||
| </Authorized> | |||
| <NotAuthorized> | |||
| <a href="authentication/login">Connexion</a> | |||
| </NotAuthorized> | |||
| </AuthorizeView> | |||
| @code { | |||
| private async Task BeginLogOut(MouseEventArgs args) | |||
| { | |||
| await SignOutManager.SetSignOutState(); | |||
| Navigation.NavigateTo("authentication/logout"); | |||
| } | |||
| } | |||
| 8. Pages/Authentication.razor | |||
| ============================= | |||
| @page "/authentication/{action}" | |||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | |||
| <RemoteAuthenticatorView Action="@Action" /> | |||
| @code { | |||
| [Parameter] public string? Action { get; set; } | |||
| } | |||