Сабж
Вроде делаю все по инструкции.
Вот код
Кодирование в base64 происходит через библиотеку https://github.com/neosmart/UrlBase64/ так как нужно URL safe Base64
string code_challenge;
byte[] key = GetByteArray();
Метод который генерирует рандомные байты.
public static byte[] GetByteArray()
{
Random rnd = new Random();
byte[] b = new byte[32];
rnd.NextBytes(b);
return b;
}
Вот инструкция
To create a code challenge your application will first need to create a one time use code verifier. A simple way to do this is to generate 32 random bytes and base64url encode them. Store this code verifier as you’ll need it in a later step. To create a corresponding code challenge, SHA-256 hash the code verifier, and then base64url encode the raw hash output. The base64url encoding is defined in RFC 4648 and should not contain padding. If you’d like to see an example of creating a code challenge in Python you can find that here. Feel free to contribute examples in other languages to this repository to help others.
Делаю:
using (SHA256 mySHA256 = SHA256.Create())
{
//получаем хеш ключа
var hashValue = mySHA256.ComputeHash(key);
// кодируем хеш в base64
var base64key = UrlBase64.Encode(hashValue);
//Кодируем оригинальный ключь в base64
var base64original = UrlBase64.Encode(key);
code_challenge = base64key;
Console.WriteLine();
Console.WriteLine(base64original);
Console.WriteLine();
}
Делаю ссылку по которой нужно перейти
string url = @$"https://login.eveonline.com/v2/oauth/authorize/?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%2Fcallback%2F&client_id=89d8c12fd57543b2809c45e6466f78fe&scope=esi-characters.read_blueprints.v1&code_challenge={code_challenge}&code_challenge_method=S256&state=DDDDD";
Перехожу по этой ссылке и получаю код.
Далее в postman отправляю POST запрос. Вот инструкция.
Now that your application has the authorization code, it needs to send a POST request to https://login.eveonline.com/v2/oauth/token with a payload containing the returned authorization code, the client ID of your application, and the original URL safe Base 64 encoded 32 byte string that was randomly created for the code challenge in step 3.
Получаю ответ:
{
"error": "invalid_grant",
"error_description": "Failed code verification challenge."
}
code_verifier
я отправляю не тот код который послал в URL когда переходила по нему. Я не понимаю что я делаю не так, вроде создал байты, потом закодировал. Что не так?Ссылка на полную инструкцию https://docs.esi.evetech.net/docs/sso/native_sso_flow.html
UPD Это мое приложение, я его создал по инструкции в панели.