# Piramal Seva Setu - Microsoft Entra SSO Configuration

Seva Setu supports Microsoft Entra OAuth 2.0 / OpenID Connect using **Authorization Code Flow with PKCE (S256)**. Implicit Flow and ROPC are not used.

## Details to share with the Piramal identity team

| Parameter | Value for Seva Setu |
|---|---|
| Redirect URL | `https://sevasetu.chlsoftech.com/auth/sso/callback` |
| Authentication platform | **Web** |
| API Permissions | **Delegated** |
| Delegated permissions / scopes | OpenID Connect: `openid`, `profile`, `email` |
| Application API permissions | **None required for Phase 1** |
| OAuth flow | Authorization Code Flow with PKCE (`S256`) |
| Implicit Flow | Not used |
| ROPC | Not used |

`openid`, `profile`, and `email` are OpenID Connect delegated scopes. Phase 1 does not call Microsoft Graph and does not require application permissions. Therefore the Workload ID Premium/Public IP requirement described for application API permissions is not applicable unless the integration scope expands later.

## Details required back from Piramal

Please provide:

- Microsoft Entra **Tenant ID**
- Application / **Client ID**
- **Client Secret** value (not the Secret ID)
- Client secret expiry date so rotation can be planned before the 12-month expiry
- Confirmation that the redirect URI above is registered exactly as a **Web** redirect URI
- Confirmation that the OpenID Connect delegated scopes (`openid`, `profile`, `email`) are permitted/consented
- Optional: approved post-logout URL / logout policy if single sign-out is required later

## Production environment variables

```text
SSO_ENABLED=true
SSO_TENANT_ID=<tenant-guid>
SSO_CLIENT_ID=<application-client-id>
SSO_CLIENT_SECRET=<client-secret-value>
SSO_REDIRECT_URI=https://sevasetu.chlsoftech.com/auth/sso/callback
SSO_SCOPES=openid profile email
SSO_PROMPT=
```

Never commit the client secret to source control. Store it only in the production `.env` / approved secret store with restricted file permissions.

## User-level authentication control

Employee Master now has an **Authentication** section:

- **Piramal SSO**: local passwords are disabled. The first successful Entra login matches the user's official email and binds the Entra object ID (`oid`) to the Seva Setu user.
- **Local ID & password**: Microsoft SSO is not used for that account. Admin assigns a Login ID and initial password; the user can change the password from My Profile.

Changing a user from Local to SSO clears the local password. Changing from SSO to Local clears the SSO binding. Admin can also explicitly reset an existing SSO binding if the employee's Entra identity changes.

## Security behaviour

- OAuth `state` is validated to protect the callback from CSRF.
- A random `nonce` is included and validated in the ID token.
- PKCE uses SHA-256 (`S256`).
- The ID token signature, issuer, audience and expiry are validated using Microsoft Entra's published JWKS metadata.
- SSO only authenticates users already present and enabled in the Seva Setu Employee Master.
- A successful Entra login does not auto-create an employee account.
- Users marked as Local cannot log in via SSO, and SSO users cannot use local passwords.
- Production session cookies are Secure, HttpOnly and SameSite=Lax.
