allegro / allegro/allegro-api

[NEWS] Autoryzacja użytkownika - udostępniamy mechanizm PKCE / User authorization - PKCE-enhanced Authorization Code Flow

Abierto
#2,682 17 comentarios 0 reacciones 1 asignado Reclamado por @PrzemyslawLukanowski Ver en GitHub
News
Lenguaje dominante
Sin datos de lenguaje
Estrellas
244
Forks
40
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Udostępniliśmy mechanizm [PKCE](https://tools.ietf.org/html/rfc7636) (Proof Key for Code Exchange), który możesz użyć podczas [autoryzacji użytkownika](https://developer.allegro.pl/auth/#app). Dzięki niemu zabezpieczysz swoją aplikację przed wykorzystaniem kodu autoryzacyjnego (**authorization code**) przez złośliwe oprogramowanie.

Aby z niego skorzystać, wygeneruj we własnym zakresie **code_verifier** - musi to być losowy ciąg znaków o długości pomiędzy 43 a 128 znaków, użyjesz go podczas żądania o token. Następnie w procesie autoryzacji dodaj dwa parametry:

- **code_challenge** - kod na potrzeby mechanizmu PKCE, jego wartość zależy od sposobu szyfrowania, który określisz w code_challenge_method,
- **code_challenge_method** - sposób szyfrowania code_challenge - może przyjmować jedną z dwóch wartości:
- **S256** - oznacza, że code_challenge jest zahashowanym (algorytmem SHA-256) code_verifier, Skorzystaj z tej wersji wartości - zapewnia większe bezpieczeństwo ze względu na użyte hashowanie,
- **plain** - oznacza, że wartość parametru code_challenge będzie równa wartości code_verifier.

Poniżej znajdziesz przykłady żądań HTTP dla **code_verifier** = KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI.

Dla **code_challenge_method=S256**:

`https://allegro.pl/auth/oauth/authorize?response_type=code&client_id=a21...6be&redirect_uri=http://exemplary.redirect.uri&code_challenge_method=S256&code_challenge=a69se03ZmsPhTLYQKHpGUH7m5waf-U8D-5pTwFRgLI4
`

Dla **code_challenge_method=plain**:

`https://allegro.pl/auth/oauth/authorize?response_type=code&client_id=a21...6be&redirect_uri=http://exemplary.redirect.uri&code_challenge_method=plain&code_challenge=KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI`

Następnie, na etapie żądania o token, jako code_verifier przekaż tę samą wartość, jaką określiłeś wcześniej:

`curl -X POST -H 'Authorization: Basic YTI...Hg=' 'https://allegro.pl/auth/oauth/token?grant_type=authorization_code&code=pOPEy9Tq94aEss540azzC7xL6nCJDWto&redirect_uri=http://exemplary.redirect.uri&code_verifier=KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI'`

Więcej informacji znajdziesz w naszym poradniku - [autoryzacja użytkownika](https://developer.allegro.pl/auth/#user).

-----

We have introduced [PKCE ](https://tools.ietf.org/html/rfc7636)(Proof Key for Code Exchange) mechanism, which you can use in the [user authorization process](https://developer.allegro.pl/auth/#app). Owing to the PKCE, you can protect your application against the use of **authorization_code** by malicious software.

To use it, generate **code_verifier** by yourself - it should be a random string containing between 43 and 128 characters, which you will use in access token request. Then in the authorization process, add two parameters:

- **code_challenge** - code for the PKCE mechanism, its value depends on the encryption method, which you specify in the code_challenge_method,
- **code_challenge_method** - code_challenge encryption method. It can take one of two values:
- **S256** - means that the code_challenge is encrypted (with SHA-256 algorithm) code_verifier. Use this value - it provides better safety due to the encryption used,
- **plain** - means that the code_challenge value will be equal to the code_verifier value.

Below you can find examples of HTTP requests for
**code_verifier** = KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI.

For **code_challenge_method=S256**:

`https://allegro.pl/auth/oauth/authorize?response_type=code&client_id=a21...6be&redirect_uri=http://exemplary.redirect.uri&code_challenge_method=S256&code_challenge=a69se03ZmsPhTLYQKHpGUH7m5waf-U8D-5pTwFRgLI4`

For **code_challenge_method=plain**:

`https://allegro.pl/auth/oauth/authorize?response_type=code&client_id=a21...6be&redirect_uri=http://exemplary.redirect.uri&code_challenge_method=plain&code_challenge=KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI`

Then, when you’re requesting for access token, as code_verifier provide the same value as you specified earlier:

`curl -X POST -H 'Authorization: Basic YTI...Hg=' 'https://allegro.pl/auth/oauth/token?grant_type=authorization_code&code=pOPEy9Tq94aEss540azzC7xL6nCJDWto&redirect_uri=http://exemplary.redirect.uri&code_verifier=KnAijeNvdSeloYlVcOh3HRmgZX57wDeVHiwRFQKO2F9DdBI'`

You will find more information in our guide - [user authorization](https://developer.allegro.pl/en/auth/#user).

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.