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

# Auth

## POST /api/hosts/adm/authenticate

> To Fetch Auth Token for a Host

```json
{"openapi":"3.1.1","info":{"title":"NetMaker","version":"1.4.0"},"tags":[],"servers":[{"url":"http://api.demo.netmaker.io"}],"paths":{"/api/hosts/adm/authenticate":{"post":{"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.SuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}}},"summary":"To Fetch Auth Token for a Host","tags":["Auth"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.AuthParams"}}},"description":"Authentication parameters","required":true}}}},"components":{"schemas":{"models.SuccessResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.ErrorResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.AuthParams":{"properties":{"id":{"type":"string"},"macaddress":{"type":"string"},"password":{"type":"string"}},"type":"object"}}}}
```

## POST /api/users/{username}/auth/complete-totp

> Verify and complete setting up TOTP 2FA for a user

```json
{"openapi":"3.1.1","info":{"title":"NetMaker","version":"1.4.0"},"tags":[],"servers":[{"url":"http://api.demo.netmaker.io"}],"security":[{"oauth":[]}],"paths":{"/api/users/{username}/auth/complete-totp":{"post":{"parameters":[{"schema":{"type":"string"},"description":"Username","in":"path","name":"username","required":true}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.SuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}}},"summary":"Verify and complete setting up TOTP 2FA for a user","tags":["Auth"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.UserTOTPVerificationParams"}}},"description":"TOTP verification parameters","required":true}}}},"components":{"schemas":{"models.SuccessResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.ErrorResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.UserTOTPVerificationParams":{"properties":{"otp_auth_url":{"type":"string"},"otp_auth_url_signature":{"type":"string"},"totp":{"type":"string"}},"type":"object"}}}}
```

## POST /api/users/{username}/auth/init-totp

> Initiate setting up TOTP 2FA for a user

```json
{"openapi":"3.1.1","info":{"title":"NetMaker","version":"1.4.0"},"tags":[],"servers":[{"url":"http://api.demo.netmaker.io"}],"security":[{"oauth":[]}],"paths":{"/api/users/{username}/auth/init-totp":{"post":{"parameters":[{"schema":{"type":"string"},"description":"Username","in":"path","name":"username","required":true}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.TOTPInitiateResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}}},"summary":"Initiate setting up TOTP 2FA for a user","tags":["Auth"]}}},"components":{"schemas":{"models.TOTPInitiateResponse":{"properties":{"otp_auth_url":{"type":"string"},"otp_auth_url_signature":{"type":"string"},"qr_code":{"type":"string"}},"type":"object"},"models.ErrorResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"}}}}
```

## POST /api/users/{username}/auth/verify-totp

> Verify a user's TOTP token

```json
{"openapi":"3.1.1","info":{"title":"NetMaker","version":"1.4.0"},"tags":[],"servers":[{"url":"http://api.demo.netmaker.io"}],"paths":{"/api/users/{username}/auth/verify-totp":{"post":{"parameters":[{"schema":{"type":"string"},"description":"Username","in":"path","name":"username","required":true}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.SuccessfulUserLoginResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}}},"summary":"Verify a user's TOTP token","tags":["Auth"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.UserTOTPVerificationParams"}}},"description":"TOTP verification parameters","required":true}}}},"components":{"schemas":{"models.SuccessfulUserLoginResponse":{"properties":{"authToken":{"type":"string"},"userName":{"type":"string"}},"type":"object"},"models.ErrorResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.UserTOTPVerificationParams":{"properties":{"otp_auth_url":{"type":"string"},"otp_auth_url_signature":{"type":"string"},"totp":{"type":"string"}},"type":"object"}}}}
```

## POST /api/users/adm/authenticate

> Authenticate a user to retrieve an authorization token

```json
{"openapi":"3.1.1","info":{"title":"NetMaker","version":"1.4.0"},"tags":[],"servers":[{"url":"http://api.demo.netmaker.io"}],"paths":{"/api/users/adm/authenticate":{"post":{"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.SuccessResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.ErrorResponse"}}}}},"summary":"Authenticate a user to retrieve an authorization token","tags":["Auth"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/models.UserAuthParams"}}},"description":"Authentication parameters","required":true}}}},"components":{"schemas":{"models.SuccessResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.ErrorResponse":{"properties":{"code":{"type":"integer"},"message":{"type":"string"},"response":{}},"type":"object"},"models.UserAuthParams":{"properties":{"password":{"type":"string"},"username":{"type":"string"}},"type":"object"}}}}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.netmaker.io/api-spec/auth.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
