# AuthResource

Canonical page: https://docs.ovok.com/java-sdk/reference/auth-resource

```java
public final class AuthResource
```

Signs users in and out and manages their account. Get it from [`Ovok.auth()`](/java-sdk/reference/ovok#auth). User sign-in needs a client built without a client secret.

## Methods [#methods]

### sessions [#sessions]

```java
public AuthSessionsResource sessions()
```

Returns the signed-in user's sessions.

**Returns:** the sessions resource

### login [#login]

```java
public LoginResult login(LoginCredentials credentials) throws IOException, InterruptedException
```

Signs a user in with email and password. Starts a PKCE sign-in (`POST /auth/tenant/{profileType}/login/start`) and, unless MFA is required, exchanges the code for tokens (`POST /auth/tenant/{profileType}/login/token`) and stores the session.

**Parameters:**

- `credentials`: the email, password and profile type

**Returns:** the session, or the MFA challenge to answer with [`verifyMfa`](#verifymfa)

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

```java
public LoginResult login(
        LoginCredentials credentials,
        RequestOptions options) throws IOException, InterruptedException
```

Signs a user in with email and password. Starts a PKCE sign-in (`POST /auth/tenant/{profileType}/login/start`) and, unless MFA is required, exchanges the code for tokens (`POST /auth/tenant/{profileType}/login/token`) and stores the session.

**Parameters:**

- `credentials`: the email, password and profile type
- `options`: per-request options, such as the timeout

**Returns:** the session, or the MFA challenge to answer with [`verifyMfa`](#verifymfa)

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

### verifyMfa [#verifymfa]

```java
public LoginResult verifyMfa(
        MfaChallenge challenge,
        String code) throws IOException, InterruptedException
```

Completes a sign-in that needs MFA. Verifies the code (`POST /auth/tenant/{profileType}/login/mfa`), exchanges it for tokens and stores the session.

**Parameters:**

- `challenge`: the challenge from [`login`](#login)
- `code`: the one-time code

**Returns:** the signed-in result

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

```java
public LoginResult verifyMfa(
        MfaChallenge challenge,
        String code,
        RequestOptions options) throws IOException, InterruptedException
```

Completes a sign-in that needs MFA. Verifies the code (`POST /auth/tenant/{profileType}/login/mfa`), exchanges it for tokens and stores the session.

**Parameters:**

- `challenge`: the challenge from [`login`](#login)
- `code`: the one-time code
- `options`: per-request options, such as the timeout

**Returns:** the signed-in result

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

### register [#register]

```java
public RegisterResult register(Map<String, ?> details) throws IOException, InterruptedException
```

Registers a patient and signs them in (`POST /auth/tenant/Patient/register`).

**Parameters:**

- `details`: `email`, `password`, `passwordConfirm`, and optionally `name`, `surname`, `continueAsPatientToken`

**Returns:** the session, or a clinician-invite result

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the password and its confirmation differ
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

```java
public RegisterResult register(
        Map<String, ?> details,
        RequestOptions options) throws IOException, InterruptedException
```

Registers a patient and signs them in (`POST /auth/tenant/Patient/register`).

**Parameters:**

- `details`: `email`, `password`, `passwordConfirm`, and optionally `name`, `surname`, `continueAsPatientToken`
- `options`: per-request options, such as the timeout

**Returns:** the session, or a clinician-invite result

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the password and its confirmation differ
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

### registerPractitioner [#registerpractitioner]

```java
public Session registerPractitioner(Map<String, ?> details) throws IOException, InterruptedException
```

Registers a practitioner and signs them in (`POST /auth/tenant/Practitioner/register`).

**Parameters:**

- `details`: `email`, `password`, `passwordConfirm`, and optionally `name`, `surname`

**Returns:** the new session

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the password and its confirmation differ
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

```java
public Session registerPractitioner(
        Map<String, ?> details,
        RequestOptions options) throws IOException, InterruptedException
```

Registers a practitioner and signs them in (`POST /auth/tenant/Practitioner/register`).

**Parameters:**

- `details`: `email`, `password`, `passwordConfirm`, and optionally `name`, `surname`
- `options`: per-request options, such as the timeout

**Returns:** the new session

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the password and its confirmation differ
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

### socialLogin [#sociallogin]

```java
public Session socialLogin(
        String provider,
        Map<String, ?> credential) throws IOException, InterruptedException
```

Signs a user in with an external identity provider (`POST /auth/external/{provider}`).

**Parameters:**

- `provider`: the provider name, such as `google`
- `credential`: the provider credential; an `internalId` entry is sent as a query parameter

**Returns:** the new session

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the config has no client ID or has a client secret

```java
public Session socialLogin(
        String provider,
        Map<String, ?> credential,
        RequestOptions options) throws IOException, InterruptedException
```

Signs a user in with an external identity provider (`POST /auth/external/{provider}`).

**Parameters:**

- `provider`: the provider name, such as `google`
- `credential`: the provider credential; an `internalId` entry is sent as a query parameter
- `options`: per-request options, such as the timeout

**Returns:** the new session

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the config has no client ID or has a client secret

### current [#current]

```java
public Session current()
```

Returns the stored user session without a network call.

**Returns:** the current session, or `null` when signed out or using client credentials

### me [#me]

```java
public JsonNode me() throws IOException, InterruptedException
```

Reads the signed-in user's profile and project (`GET /auth/me`).

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode me(RequestOptions options) throws IOException, InterruptedException
```

Reads the signed-in user's profile and project (`GET /auth/me`).

**Parameters:**

- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### changePassword [#changepassword]

```java
public JsonNode changePassword(Map<String, ?> request) throws IOException, InterruptedException
```

Changes the signed-in user's password (`PATCH /v2/auth/change-password`).

**Parameters:**

- `request`: `oldPassword` and `newPassword`

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if either password is missing

```java
public JsonNode changePassword(
        Map<String, ?> request,
        RequestOptions options) throws IOException, InterruptedException
```

Changes the signed-in user's password (`PATCH /v2/auth/change-password`).

**Parameters:**

- `request`: `oldPassword` and `newPassword`
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if either password is missing

### resetPassword [#resetpassword]

```java
public JsonNode resetPassword(Map<String, ?> request) throws IOException, InterruptedException
```

Requests a password-reset email (`POST /v2/auth/reset-password`).

**Parameters:**

- `request`: the reset request; `clientId` defaults to the configured client ID

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode resetPassword(
        Map<String, ?> request,
        RequestOptions options) throws IOException, InterruptedException
```

Requests a password-reset email (`POST /v2/auth/reset-password`).

**Parameters:**

- `request`: the reset request; `clientId` defaults to the configured client ID
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### completePasswordReset [#completepasswordreset]

```java
public JsonNode completePasswordReset(
        Map<String, ?> request) throws IOException, InterruptedException
```

Sets a new password from a reset link (`POST /v2/auth/reset-password/process`).

**Parameters:**

- `request`: the reset token and new password

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode completePasswordReset(
        Map<String, ?> request,
        RequestOptions options) throws IOException, InterruptedException
```

Sets a new password from a reset link (`POST /v2/auth/reset-password/process`).

**Parameters:**

- `request`: the reset token and new password
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### deleteAccount [#deleteaccount]

```java
public JsonNode deleteAccount(Map<String, ?> request) throws IOException, InterruptedException
```

Deletes the signed-in user's account (`DELETE /auth/delete`).

**Parameters:**

- `request`: the deletion request

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode deleteAccount(
        Map<String, ?> request,
        RequestOptions options) throws IOException, InterruptedException
```

Deletes the signed-in user's account (`DELETE /auth/delete`).

**Parameters:**

- `request`: the deletion request
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### logout [#logout]

```java
public void logout() throws IOException, InterruptedException
```

Ends the current session (`DELETE /auth/session/current`) and clears it locally, even if the call fails.

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret

```java
public void logout(RequestOptions options) throws IOException, InterruptedException
```

Ends the current session (`DELETE /auth/session/current`) and clears it locally, even if the call fails.

**Parameters:**

- `options`: per-request options, such as the timeout

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConfigException`](/java-sdk/reference/ovok-config-exception): if the client was built with a client secret
