---
title: "Client API: Setting up Authentication and Authorization"
url: "https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization"
version: "6.2"
language: "csharp"
---

# Client API: Setting up Authentication and Authorization

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization.java.md), [Node.js](https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - **Authentication and authorization** are based on [Client X.509 Certificates](https://docs.ravendb.net/6.2/server/security/authorization/security-clearance-and-permissions.md).
>
> - When your RavenDB instance runs on HTTPS, the server has a **Server Certificate** loaded.  
>   Your application must use a **Client Certificate** in order to access this secure server.
>
> - Obtain a Client Certificate from your cluster admin.  
>   The Client Certificate is generated by the admin from the [Studio](https://docs.ravendb.net/6.2/server/security/authentication/certificate-management.md).
>
> - The security clearance (authorization level) for the generated Client Certificate is set during the process of generating the
>   certificate.
>
> - Pass your Client Certificate to the Document Store before initialization, as shown in the example code
>   [below](#example---initializing-document-store-with-a-client-certificate).  
>   The server will use this certificate to authenticate the client when connection is established.

## Example - Initializing Document Store With a Client Certificate

```csharp
// Load a X.509 certificate
X509Certificate2 clientCertificate = new X509Certificate2("C:\\path_to_your_pfx_file\\cert.pfx");

using (IDocumentStore store = new DocumentStore()
{
  // Pass your certificate to the `Certificate` property
  Certificate = clientCertificate,
  Database = "your_database_name",
  Urls = new[] {"https://your_RavenDB_server_URL"}
}.Initialize())
{
  // Do your work here
}
```

## See also

- [Installation : Setup Wizard Walkthrough](https://docs.ravendb.net/6.2/start/installation/setup-wizard/overview.md)
- [What is a Document Store](https://docs.ravendb.net/6.2/client-api/what-is-a-document-store.md)
- [Creating a Document Store](https://docs.ravendb.net/6.2/client-api/creating-document-store.md)
- [Setting up Default Database](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.md)
- [Security Overview](https://docs.ravendb.net/6.2/server/security/overview.md)
- [Security Clearance &amp; Permissions](https://docs.ravendb.net/6.2/server/security/authorization/security-clearance-and-permissions.md)
- [Client Certificiate Usage](https://docs.ravendb.net/6.2/server/security/authentication/client-certificate-usage.md)
- [Certificate Management](https://docs.ravendb.net/6.2/server/security/authentication/certificate-management.md)
