> 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/fin/api-dokumentaatio/valtuutus-apikey-tunnistetiedot-tai-oauth-2.0.md).

# Valtuutus: ApiKey, tunnistetiedot tai OAuth 2.0

GeoPard-ratkaisu käyttää [AWS Cognitoa](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) valtuutusprosessiin.

Suosittelemme tarkistamaan kaikki valtuutusvaihtoehdot. Valinta riippuu erityisestä käyttötapauksesta. Lisätietoja käytöstä on kuvattu kussakin alla olevassa vaihtoehdossa.

## Vaihtoehto 1: Käyttäjätunnuksen ja salasanan käyttö

Valtuutus "käyttäjätunnus"- ja "salasana"-menetelmällä on yksi mahdollinen lähestymistapa. Tässä tapauksessa sähköpostirekisteröinti on tehtävä (ei sosiaalisen median kautta).&#x20;

{% hint style="info" %}
Lähestymistapaa ***suositellaan integroitavaksi API-tasolla (BackEnd)*** ja kaikki pyynnöt GeoPard-APIin välitetään omistetun erillisen palvelun (mikropalvelun) kautta.
{% endhint %}

### Kirjautumispyyntö&#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 %}

### Kirjautumisvastaus

{% hint style="danger" %}
Token on JWT, jonka voimassaoloaika on 30 minuuttia.\
\
Parhaana käytäntönä on tallentaa yksi token ja käyttää sitä kaikissa pyynnöissä, tarkistaen sen vanhenemisaika ja hakien uusi token vanhentumisen yhteydessä (tai hieman ennen sitä).
{% endhint %}

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

## Vaihtoehto 2: OAuth 2.0

AWS Cognito tukee OAuth 2.0 -protokollaa valtuutukseen. Yleiskuvaus on kuvattu artikkelissa [Cognito OAuth2 -opas](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), alakappaleessa Authorization Code Grant on GeoPard-tapauksessa mielenkiintoisin.&#x20;

{% hint style="info" %}
Lähestymistapaa ***suositellaan integroimaan GeoPard käyttöliittymätasolla (FrontEnd)***. Integraatio toimii molempiin suuntiin tietojen lähettämiseksi/vastaanottamiseksi GeoPardista/GeoPardiin.
{% endhint %}

Lyhyesti kerrottuna:

1. Sovelluksesi on ohjattava käyttäjä GeoPard Cognitoon kirjautumista tai rekisteröitymistä varten.&#x20;

Esimerkki:

{% 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 %}

Ota yhteyttä GeoPard-tiimiin saadaksesi sovelluksellesi yksilöllisen `client_id`.

2. Uudelleenohjattu URL vastaanottaa varmennuskoodin `koodi` seuraavaa vaihetta varten.

Uudelleenohjattu URL näyttää tältä [`http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a&state=54321`](http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a\&state=54321).

3. Sovelluksesi on vaihdettava `koodi` kohteelle `tokenit` (`access_token`, `refresh_token`, `id_token`).

Esimerkki:

{% 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 %}

## Vaihtoehto 3: API-avain

Nopea pääsy WMS- ja WFS-palveluihin on ajoittain tarpeen. Siksi on mahdollista käyttää GeoPard-tilille automaattisesti luotua API-avainta.

API-avain löytyy `apiAvain` UserData GraphQL-olion  `apiAvain` attribuutista. Ohjeet hakemiseksi [TÄSSÄ](/geopard-tutorials/fin/api-dokumentaatio/geopard-api-pyyntojen-yleiskatsaus/38.-kysely-hae-userdata.md).

{% hint style="danger" %}
`apiAvain` on käytettävä yhdessä `/geo` päätepisteiden KANSSA VAIN.
{% endhint %}

Käyttö:

1. Kuten `geopardApiKey` parametri GET-pyynnön URL:issa.
2. Kuten `X-API-Key` otsikkona MISSÄ TAHANSA pyynnössä.<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/fin/api-dokumentaatio/valtuutus-apikey-tunnistetiedot-tai-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.
