# Identity policy

Source: https://www.pontive.com/docs/api-reference/management/identity-policy

Base URL: `https://api.{region}.pontive.com/v1` (operations that name another server say so).

Authentication: send `Authorization: Bearer <token>` with a secret key (`pontive_sk_…`, which implies its instance) or an access token issued for this API. A token that can reach several instances also names one with `X-Pontive-Instance-ID: inst_…`. Secret keys are for servers only.

## Get identity policy

```http
GET https://api.{region}.pontive.com/v1/authn/identity-policy
```

Get the instance's identity policy (email, phone, and username rules). If none has been configured, the default policy is returned.

Operation ID: `GetIdentityPolicy`

### Responses

- `200` OK: IdentityPolicy
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Update identity policy

```http
PATCH https://api.{region}.pontive.com/v1/authn/identity-policy
```

Patch the instance's identity policy. Omitted sub-policies and fields are left unchanged.

Operation ID: `UpdateIdentityPolicy`

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `If-Match` | string |  | The ETag the document was read with: a stale one is refused 412 precondition_failed (D42) |

### Request body (`application/json`, required): UpdateIdentityPolicyRequest

Update payload

### Responses

- `200` OK: IdentityPolicy
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `412` precondition_failed: the document changed since it was read: ErrResponse
- `500` Internal Server Error: ErrResponse

## Preview email rules

```http
POST https://api.{region}.pontive.com/v1/authn/identity-policy/email/preview
```

Count the active users whose email the given rules would refuse at sign-in, were they enforced there (email.enforce_at_signin), with a count per rule. Changes nothing. Ask before turning enforcement on, or tightening a rule while it is on, to see who would be locked out.

Operation ID: `PreviewEmailPolicy`

### Request body (`application/json`, required): PreviewEmailPolicyRequest

Candidate email rules

### Responses

- `200` OK: EmailPolicyPreview
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Schemas

### IdentityPolicy

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `created_at` | string |  |  |
| `email` | EmailPolicy |  |  |
| `object` | string |  |  |
| `phone` | PhonePolicy |  |  |
| `updated_at` | string |  |  |
| `username` | UsernamePolicy |  |  |

### ErrResponse

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | ErrBody |  |  |

### UpdateIdentityPolicyRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `email` | EmailPolicyUpdate |  |  |
| `phone` | PhonePolicyUpdate |  |  |
| `username` | UsernamePolicyUpdate |  |  |

### PreviewEmailPolicyRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_disposable` | boolean |  |  |
| `allow_plus_addressing` | boolean |  |  |
| `domain_restriction` | DomainRestriction |  |  |

### EmailPolicyPreview

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `affected_users` | integer |  | AffectedUsers break at least one rule. |
| `by_rule` | Record<string, integer> |  | ByRule counts the users breaking each rule, by its code (email_domain_not_allowed, email_domain_blocked, email_plus_addressing_not_allowed, email_disposable_not_allowed). A user breaking two rules counts under both. |
| `checked_users` | integer |  | CheckedUsers are the active users with an email; all were checked. |
| `object` | string |  |  |

### EmailPolicy

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_disposable` | boolean |  |  |
| `allow_plus_addressing` | boolean |  |  |
| `domain_restriction` | DomainRestriction |  |  |
| `enforce_at_signin` | boolean |  | EnforceAtSignIn also holds existing users to the rules at sign-in. Off by default. |

### PhonePolicy

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `country_restriction` | CountryRestriction |  |  |
| `require_verification_for_login` | boolean |  |  |

### UsernamePolicy

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_changes` | boolean |  |  |
| `allowed_characters` | "alphanumeric" \| "alphanumeric_underscore" |  |  |
| `change_cooldown_days` | integer |  |  |
| `enabled` | boolean |  |  |
| `max_length` | integer |  |  |
| `min_length` | integer |  |  |
| `reserved_usernames` | string[] |  |  |

### ErrBody

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string |  | Code is the spec's machine-readable code for this error, in snake case: a domain code such as seat_limit_reached where the refusal has one, otherwise a generic one such as permission_denied, not_found, conflict, invalid_request or service_unavailable. |
| `details` | ErrDetail[] |  | Details are per-field findings, present only on a refusal that has them, e.g. a 422 invalid_theme names each invalid value by its path, a 422 package_invalid each problem, and a 409 capability_in_use each count by its name. |
| `doc_url` | string |  | DocURL links to documentation about this error, when available. |
| `message` | string |  | Message is a human-readable description of what went wrong. |
| `object` | string |  | Object is the discriminator; always "error". |
| `param` | string |  | Param names the request parameter this error refers to, when applicable. |
| `type` | "validation_error" \| "authentication_error" \| "authorization_error" \| "not_found" \| "conflict_error" \| "rate_limit_error" \| "internal_error" |  | Type is the error's category, set by its HTTP status: one of validation_error, authentication_error, authorization_error, not_found, conflict_error, rate_limit_error, internal_error. |

### EmailPolicyUpdate

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_disposable` | boolean |  |  |
| `allow_plus_addressing` | boolean |  |  |
| `domain_restriction` | DomainRestriction |  |  |
| `enforce_at_signin` | boolean |  |  |

### PhonePolicyUpdate

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `country_restriction` | CountryRestriction |  |  |
| `require_verification_for_login` | boolean |  |  |

### UsernamePolicyUpdate

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_changes` | boolean |  |  |
| `allowed_characters` | "alphanumeric" \| "alphanumeric_underscore" |  |  |
| `change_cooldown_days` | integer |  |  |
| `clear_reserved_usernames` | boolean |  |  |
| `enabled` | boolean |  |  |
| `max_length` | integer |  |  |
| `min_length` | integer |  |  |
| `reserved_usernames` | string[] |  |  |

### DomainRestriction

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `domains` | string[] |  |  |
| `mode` | "none" \| "allow" \| "block" |  |  |

### CountryRestriction

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `countries` | string[] |  |  |
| `mode` | "none" \| "allow" \| "block" |  |  |

### ErrDetail

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `field` | string |  | Field is where the finding is: for a theme, its dotted path. |
| `message` | string |  | Message is what is wrong there. |
