> For the complete documentation index, see [llms.txt](https://docs.geopard.tech/geopard-tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.geopard.tech/geopard-tutorials/bg/dokumentaciya-na-api/avtorizaciya-apikey-credentials-ili-oauth-2.0.md).

# Авторизация: ApiKey, Credentials или OAuth 2.0

Решението GeoPard използва [AWS Cognito](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) за процедурата по удостоверяване.

Препоръчваме да проверите всички опции за авторизация. Изборът зависи от конкретния случай на употреба. Повече подробности за използването са описани във всяка опция по-долу.

## Опция 1: Използване на идентификационни данни

Удостоверяване с „потребителско име“ и „парола“ е един от възможните подходи. В този случай регистрацията по имейл трябва да бъде извършена (без използване на социални мрежи).&#x20;

{% hint style="info" %}
Подходът ***е препоръчителен за интеграция на ниво API (BackEnd)*** и всички заявки към GeoPard API се проксират чрез специална отделна услуга (микросървис).
{% endhint %}

### Заявка за вход&#x20;

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request POST 'https://api.geopard.tech/login' \
--header 'Content-Type: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{"username":"<email_address>","password":"<password>"}'
```

{% endcode %}

### Отговор при вход

{% hint style="danger" %}
Токенът е JWT със срок на валидност 30 минути.\
\
Най-добра практика е да се съхранява един токен и да се използва повторно за всички заявки, като се проверява времето на изтичане и се извлича нов токен, когато изтече (или малко преди това).
{% endhint %}

```json
{
    "token": "<token_to_use_in_geopard_api>"
}
```

## Опция 2: OAuth 2.0

AWS Cognito поддържа протокол OAuth 2.0 за авторизация. Общият преглед е описан в статията [Cognito OAuth2 ръководство](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), подтемата Authorization Code Grant е най-интересна за случая с GeoPard.&#x20;

{% hint style="info" %}
Подходът ***е препоръчително да се интегрира GeoPard на ниво Потребителски интерфейс (FrontEnd)***. Интеграцията работи и в двете посоки за изпращане/получаване на данни до/от GeoPard.
{% endhint %}

Накратко:

1. Вашето приложение трябва да пренасочи потребителя към GeoPard Cognito за вход или регистрация.&#x20;

Пример:

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request GET '
https://auth.geopard.tech/oauth2/authorize?response_type=code&client_id=<connect_geopard_team>&redirect_uri=http://localhost:8080&state=54321
'
```

{% endcode %}

Моля, свържете се с екипа на GeoPard, за да получите индивидуалния за вашето приложение `client_id`.

2. Пренасоченият URL ще получи проверъчен `код` за следващата стъпка.

Пренасоченият URL изглежда като [`http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a&state=54321`](http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a\&state=54321).

3. Вашето приложение трябва да разменя `код` за `токени` (`access_token`, `refresh_token`, `id_token`).

Пример:

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request POST '
https://auth.geopard.tech/oauth2/token
' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: XSRF-TOKEN=365e14e1-3c66-477e-b0ef-a9e436a834ee; csrf-state=""; csrf-state-legacy=""' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a' \
--data-urlencode 'client_id=42ajne9u466in6gaf569nth9o9' \
--data-urlencode 'redirect_uri=
http://localhost:8080
'
```

{% endcode %}

## Опция 3: API ключ

Бърз достъп до WMS и WFS понякога е необходим. Поради това е възможно да се използва GeoPard API ключ, автоматично генериран за всеки акаунт.

API ключът може да бъде намерен в `apiКлюч` атрибута на GraphQL ентитета "UserData". Инструкции как да извлечете  `apiКлюч` са предоставени [ТУК](/geopard-tutorials/bg/dokumentaciya-na-api/pregled-na-zayavkite-km-geopard-api/38.-zayavka-poluchavane-na-userdata.md).

{% hint style="danger" %}
`apiКлюч` трябва да се използва с `/geo` крайни точки САМО.
{% endhint %}

Използване:

1. Като `geopardApiKey` параметър в URL на GET заявката.
2. Като `X-API-Key` заглавка в ВСЯКА заявка.<br>


---

# 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://docs.geopard.tech/geopard-tutorials/bg/dokumentaciya-na-api/avtorizaciya-apikey-credentials-ili-oauth-2.0.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.
