allegro / allegro/allegro-api

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

未關閉
#2,682 17 則留言 0 個 reaction 已指派 1 人 已被 @PrzemyslawLukanowski 認領 在 GitHub 檢視
News
主要語言
沒有語言資料
星號
244
分支
40
PR 合併指標
30 天內沒有已合併 PR

描述

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).

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。