# Auth resource

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

{/* Generated by scripts/generate_reference.dart; do not edit. */}

## AuthResource [#authresource]

```dart
class AuthResource
```

Sign-in, registration, passwords and the account; sign-in runs anonymously.

Reached through `ovok.auth`. Every request throws an [`OvokException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokexception)
subclass when it fails.

### Constructors [#constructors]

#### AuthResource.new [#authresourcenew]

```dart
AuthResource(
  HttpClient _http,
  String _tenantCode,
  UserSession _session,
  String? _clientId,
)
```

`clientId` is the ClientApplication social sign-in and password resets go through.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `_http` | `HttpClient` | positional |  |
| `_tenantCode` | `String` | positional |  |
| `_session` | `UserSession` | positional |  |
| `_clientId` | `String?` | positional |  |

### Properties [#properties]

#### AuthResource.sessions [#authresourcesessions]

```dart
final AuthSessionsResource sessions
```

The account's sessions on the server.

### Methods [#methods]

#### AuthResource.login [#authresourcelogin]

```dart
Future<LoginResult> login({
  required ProfileType profileType,
  required String email,
  required String password,
})
```

Runs the tenant login with PKCE for the configured tenant.

Calls `POST auth/tenant/{profileType}/login/start`, then the token step.
Returns [`SignedIn`](/flutter-sdk/reference/ovok_sdk/sign-in-results#signedin), or [`MfaRequired`](/flutter-sdk/reference/ovok_sdk/sign-in-results#mfarequired) when the account needs a second factor.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `profileType` | `ProfileType` | required named |  |
| `email` | `String` | required named |  |
| `password` | `String` | required named |  |

Returns `Future<LoginResult>`.

#### AuthResource.verifyMfa [#authresourceverifymfa]

```dart
Future<LoginResult> verifyMfa(MfaChallenge challenge, String code)
```

Completes a login that returned [`MfaRequired`](/flutter-sdk/reference/ovok_sdk/sign-in-results#mfarequired) with the user's MFA `code`.

Calls `POST auth/tenant/{profileType}/login/mfa`, then the token step.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `challenge` | `MfaChallenge` | positional |  |
| `code` | `String` | positional |  |

Returns `Future<LoginResult>`.

#### AuthResource.register [#authresourceregister]

```dart
Future<RegisterResult> register(Registration registration, {String? continueAsPatientToken})
```

Registers a patient account and signs it in.

Calls `POST auth/tenant/Patient/register`. Returns [`SignedIn`](/flutter-sdk/reference/ovok_sdk/sign-in-results#signedin), or
[`ClinicianInvite`](/flutter-sdk/reference/ovok_sdk/sign-in-results#clinicianinvite) when the project routes the email to a clinician
invitation, which signs no one in. Throws [`OvokValidationException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokvalidationexception) when
the password and its confirmation differ.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `registration` | `Registration` | positional |  |
| `continueAsPatientToken` | `String?` | named |  |

Returns `Future<RegisterResult>`.

#### AuthResource.registerPractitioner [#authresourceregisterpractitioner]

```dart
Future<Session> registerPractitioner(Registration registration)
```

Registers a practitioner account and signs it in.

Calls `POST auth/tenant/Practitioner/register`. Throws
[`OvokValidationException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokvalidationexception) when the password and its confirmation differ.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `registration` | `Registration` | positional |  |

Returns `Future<Session>`.

#### AuthResource.socialLogin [#authresourcesociallogin]

```dart
Future<Session> socialLogin(
  SocialProvider provider, {
  required String internalId,
  required Map<String, dynamic> credential,
})
```

Signs in with an Apple or Google credential.

Calls `POST auth/external/{provider}`. `credential` is the provider's
sign-in result, sent as it is. Throws [`OvokConfigException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokconfigexception) when the
client was built without `clientId`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `provider` | `SocialProvider` | positional |  |
| `internalId` | `String` | required named |  |
| `credential` | `Map<String, dynamic>` | required named |  |

Returns `Future<Session>`.

#### AuthResource.current [#authresourcecurrent]

```dart
Future<Session?> current()
```

The stored session, or null when no one is signed in.

Returns `Future<Session?>`.

#### AuthResource.me [#authresourceme]

```dart
Future<Map<String, dynamic>> me()
```

Fetches the signed-in account. Calls `GET auth/me`.

Returns `Future<Map<String, dynamic>>`.

#### AuthResource.changePassword [#authresourcechangepassword]

```dart
Future<Map<String, dynamic>> changePassword({required String oldPassword, required String newPassword})
```

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

The confirmation is the app's to check; Ovok Core never receives it.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `oldPassword` | `String` | required named |  |
| `newPassword` | `String` | required named |  |

Returns `Future<Map<String, dynamic>>`.

#### AuthResource.resetPassword [#authresourceresetpassword]

```dart
Future<Map<String, dynamic>> resetPassword({
  required String email,
  required ProfileType type,
  String? clientId,
})
```

Starts a password reset for `email`. Calls `POST v2/auth/reset-password`.

`clientId` overrides the client's configured `clientId`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `email` | `String` | required named |  |
| `type` | `ProfileType` | required named |  |
| `clientId` | `String?` | named |  |

Returns `Future<Map<String, dynamic>>`.

#### AuthResource.completePasswordReset [#authresourcecompletepasswordreset]

```dart
Future<Map<String, dynamic>> completePasswordReset({
  required String id,
  required String secret,
  required String password,
})
```

Sets `password` with the `id` and `secret` from the reset email.

Calls `POST v2/auth/reset-password/process`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String` | required named |  |
| `secret` | `String` | required named |  |
| `password` | `String` | required named |  |

Returns `Future<Map<String, dynamic>>`.

#### AuthResource.deleteAccount [#authresourcedeleteaccount]

```dart
Future<Map<String, dynamic>> deleteAccount({required int days, bool wipe = false})
```

Schedules the deletion in `days`; `wipe` also deletes the medical data then.

Calls `DELETE auth/delete`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `days` | `int` | required named |  |
| `wipe` | `bool` | named | `false` |

Returns `Future<Map<String, dynamic>>`.

#### AuthResource.logout [#authresourcelogout]

```dart
Future<void> logout()
```

Ends the session on the server, and always locally, even when the server cannot be reached.

Calls `DELETE auth/session/current`.

Returns `Future<void>`.


## SocialProvider [#socialprovider]

```dart
enum SocialProvider
```

An identity provider for [`AuthResource.socialLogin`](#authresourcesociallogin).

### Values [#values]

#### SocialProvider.apple [#socialproviderapple]

```dart
static const SocialProvider apple
```

Sign in with Apple.

#### SocialProvider.google [#socialprovidergoogle]

```dart
static const SocialProvider google
```

Sign in with Google.
