> For the complete documentation index, see [llms.txt](https://docs.codemash.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codemash.io/api/membership/auth.md).

# Authentication

## Credentials authentication

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/:version/auth/credentials`

Authenticate a user using an email password pair. Also supports **GET** method with body parameters in a query string.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                            |
| -------------- | ------ | ------------------------------------------------------ |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter. |

#### Request Body

| Name     | Type   | Description                  |
| -------- | ------ | ---------------------------- |
| password | string | User's login password.       |
| userName | string | User's login e-mail address. |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

await membershipService.AuthenticateCredentialsAsync(
    "test@email.com", 
    "password123"
);
```

{% endtab %}

{% tab title="Node" %}

```csharp
```

{% endtab %}

{% tab title="PHP" %}

```php
use Codemash\CodemashClient;
use Codemash\CodemashAuth;

class CodemashService
{
    protected CodemashAuth $codemashAuth;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $this->codemashAuth = new CodemashAuth($client);
    }

    public function login()
    {
        $responseData = $codemashAuth->authenticate([
        	'userName' => 'test@email.com',
        	'password' => 'password123',
        ]);
    }
}
```

{% endtab %}
{% endtabs %}

## Microsoft authentication

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/{version}/auth/aad`

Authenticate a user using Microsoft. Also supports **GET** method with body parameters in a query string.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                            |
| -------------- | ------ | ------------------------------------------------------ |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter. |

#### Request Body

| Name | Type   | Description                                                          |
| ---- | ------ | -------------------------------------------------------------------- |
| mode | string | Mode to use for authentication. If not passed, will use the default. |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Logout

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/auth/logout`

Logout a user using any of the authentication providers.

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

await membershipService.LogoutAsync("{BEARER_TOKEN}");
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}

{% tab title="PHP" %}

```php
use Codemash\CodemashClient;
use Codemash\CodemashAuth;

class CodemashService
{
    protected CodemashAuth $codemashAuth;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $this->codemashAuth = new CodemashAuth($client);
    }

    public function logout()
    {
        $responseData = $this->codemashAuth->logout([
        	'bearerToken' => '{BEARER_TOKEN},
        ]);
    }
}
```

{% endtab %}
{% endtabs %}

## Check authentication

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/:version/auth`

Check if the user is authenticated (if authorization token is valid). Also, supports **GET** method.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

await membershipService.AuthenticateCredentialsAsync(
    "test@email.com", 
    "password123"
);
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}

{% tab title="PHP" %}

```php
use Codemash\CodemashClient;
use Codemash\CodemashAuth;

class CodemashService
{
    protected CodemashAuth $codemashAuth;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $this->codemashAuth = new CodemashAuth($client);
    }

    public function isAuthenticated()
    {
        $responseData = $this->codemashAuth->checkAuth();
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.codemash.io/api/membership/auth.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
