wasAsked.

How does authentication and authorization work in your application (Angular + .NET)?

Capgemini · Full Stack Developer · technical

Published

Year not specified · .NET, Angular, Authentication & Security

Community answers

Posted by wasAsked editorial collection

A common setup for Angular and .NET is OpenID Connect sign-in with an identity provider, JWT access tokens for the API, and policy-based authorization in ASP.NET Core. Authentication (who you are) 1. The Angular app uses a library such as angular-auth-oidc-client or MSAL Angular to start the Authorization Code flow with PKCE. 2. The user signs in at the identity provider (Microsoft Entra ID, Keycloak, Auth0 or IdentityServer). 3. Angular receives an ID token (user identity) and an access token (for the API), plus a refresh mechanism. 4. An HTTP interceptor attaches Authorization: Bearer <token> to API requests. API validation builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(o => { o.Authority = authority; o.Audience = "api://orders"; }); The API checks the token's signature, issuer, audience and expiry on every request. Authorization (what you may do) - Role- and policy-based rules: builder.Services.AddAuthorization(o => o.AddPolicy("CanApproveInvoices", p => p.RequireRole("FinanceManager"))); [Authorize(Policy = "CanApproveInvoices")] - Resource-based checks inside handlers (IAuthorizationService) for rules like "user can edit only their own team's records". - Multi-tenant apps also check the tenant claim against the data being accessed. Angular side - Route guards (canActivate / canMatch functions) hide pages from users without the right role, and directives hide buttons — purely for UX. The API must still enforce every rule. - An interceptor handles 401 (refresh token or redirect to login) and 403 (show an access-denied message). Security practices - Short-lived access tokens with refresh token rotation; avoid storing tokens in localStorage where possible, or use a BFF with HttpOnly cookies. - HTTPS everywhere, strict CORS, and least-privilege scopes. - Log sign-ins and permission failures for auditing. When answering, describe your actual project: which identity provider, how roles are assigned, and one tricky rule you implemented.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics