Имя: Пароль:
1C
 
Получить токен по API
0 Sj
 
23.09.21
22:45
Доброе время суток!

В полученной документации указано
Login:

POST /user/client/login
Content-Type: application/json
Body:
{
"client": "xx",
"secret": "xx"
}
The values for "client" and "secret" are the API credentials generated on the website (client_id
and client_secret)
The response contains an access_token which is the TOKEN to be used in all subsequent calls
to the API.
Remember that this "access_token" has an expiration time and must be regenerated by
repeating the login process.

Соответственно, у меня получилось следующее:

Процедура Тест()

    Сервер = "supplier-qa.wabi2b.com";
    Порт   = 443;
    Логин  = "[email protected]";
    Пароль = "******";
    Ресурс = "/user/client/login";

    JSON = Новый ЗаписьJSON;
    JSON.УстановитьСтроку();
    ПараметрыЗапроса = Новый Структура("client,secret", Логин,Пароль);
    ЗаписатьJSON(JSON, ПараметрыЗапроса);
    Тело = JSON.Закрыть();

    Заголовки = Новый Соответствие;
    Заголовки.Вставить("Content-type", "application/json");
    HTTPЗапрос = Новый HTTPЗапрос(Ресурс,Заголовки);
    HTTPЗапрос.УстановитьТелоИзСтроки(Тело);
    Соединение = Новый HTTPСоединение(Сервер,Порт,,,,, Новый ЗащищенноеСоединениеOpenSSL);
    Ответ = Соединение.ОтправитьДляОбработки(HTTPЗапрос);
    Сообщить(Ответ.ПолучитьТелоКакСтроку(КодировкаТекста.UTF8));

КонецПроцедуры

Ответ:
Ответ.КодСостояния = 200
Ответ.Заголовки
Ключ    Значение
"Via"    "1.1 2da695f21de77ab27a57fd348bd62648.cloudfront.net (CloudFront)"
"Vary"    "Accept-Encoding"
"Content-Security-Policy"    "default-src https: ;style-src https: 'unsafe-inline'; script-src https: 'unsafe-inline'; img-src https: data:"
"Server"    "AmazonS3"
"X-Amz-Cf-Pop"    "HEL50-C2"
"X-XSS-Protection"    "1; mode=block"
"ETag"    ""9b6f13742cbcda6de279d2bd614b0bd8""
"Strict-Transport-Security"    "max-age=63072000; includeSubdomains; preload"
"X-Cache"    "Error from cloudfront"
"Last-Modified"    "Thu, 16 Sep 2021 15:10:56 GMT"
"X-Edge-Origin-Shield-Skipped"    "0"
"Date"    "Thu, 23 Sep 2021 19:36:16 GMT"
"X-Amz-Cf-Id"    "5VKeoCA0u4aVDXIC-db3y11Chhs8EbpRqZ9-oOmnPJu2VNYbV7kQzQ=="
"X-Content-Type-Options"    "nosniff"
"Connection"    "close"
"Content-Type"    "text/html"
"X-Frame-Options"    "DENY"
"Cache-Control"    "no-cache"
"Accept-Ranges"    "bytes"
"Content-Length"    "3876"

Никаким access_token даже рядом не пахнет. Что-то неправильно делаю?
1 icipher
 
23.09.21
22:54
Ответ.ПолучитьТелоКакСтроку()
2 Sj
 
23.09.21
23:06
<!DOCTYPE html><html lang="en"><head>
  <meta charset="utf-8">
  <title>Suppliers</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" href="assets/img/wabi2b/favicon.png">
  <style type="text/css">@font-face{font-family:'Material Icons';font-style:normal;font-weight:400;src:url(https://fonts.gstatic.com/s/materialicons/v103/flUhRq6tzZclQEJ-Vdg-IuiaDsNa.woff) format('woff');}.material-icons{font-family:'Material Icons';font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;font-feature-settings:'liga';}@font-face{font-family:'Material Icons';font-style:normal;font-weight:400;src:url(https://fonts.gstatic.com/s/materialicons/v103/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2');}.material-icons{font-family:'Material Icons';font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:'liga';-webkit-font-smoothing:antialiased;}</style>
<style>@import url(https://fonts.googleapis.com/icon?family=Material+Icons&display=swap);@import url(https://fonts.googleapis.com/css?family=Rubik:300,400,500&display=swap);@import url(https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;:root{--blue:#007bff;--indigo:#6610f2;--purple:#6f42c1;--pink:#e83e8c;--red:#dc3545;--orange:#fd7e14;--yellow:#ffc107;--green:#28a745;--teal:#20c997;--cyan:#17a2b8;--white:#fff;--gray:#6c757d;--gray-dark:#343a40;--primary:#007bff;--secondary:#6c757d;--success:#28a745;--info:#17a2b8;--warning:#ffc107;--danger:#dc3545;--light:#f8f9fa;--dark:#343a40;--breakpoint-xs:0;--breakpoint-sm:576px;--breakpoint-md:768px;--breakpoint-lg:992px;--breakpoint-xl:1200px;--font-family-sans-serif:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-family-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;}*,:after,:before{box-sizing:border-box;}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,Liberation Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff;}@media print{*,:after,:before{text-shadow:none!important;box-shadow:none!important;}@page {size:a3;}body{min-width:992px!important;}}*{padding:0;margin:0;}body,html{font-family:Rubik,sans-serif;text-align:left;text-align:initial;}body{background:#ececec;overflow-x:hidden;}body::-webkit-scrollbar{width:10px;}body::-webkit-scrollbar-track{border-radius:10px;background:#d8d8d8;}body::-webkit-scrollbar-thumb{background-color:#21c063;border-radius:10px;}@media screen and (max-width:767px){body{margin-top:-10px;}}</style><link rel="stylesheet" href="styles.354b48ef7378c2acb794.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.354b48ef7378c2acb794.css"></noscript></head>

<body>
  <app-root></app-root>
<script src="runtime-es2015.ffc8161bb449441de787.js" type="module"></script><script src="runtime-es5.ffc8161bb449441de787.js" nomodule defer></script><script src="polyfills-es5.a66ae47c4935af2bea8d.js" nomodule defer></script><script src="polyfills-es2015.017f8e0e10437ee5c9bc.js" type="module"></script><script src="main-es2015.0367a7dc058b81d35710.js" type="module"></script><script src="main-es5.0367a7dc058b81d35710.js" nomodule defer></script>

</body></html>
3 polosov
 
23.09.21
23:08
Что-то не так делаешь. Куда-то редиректит похоже. Точно код 200 возвращает?
4 polosov
 
23.09.21
23:08
Хотя и это
X-Frame-Options"    "DENY"
настораживает.
5 Sj
 
23.09.21
23:27
(3) точно
6 Sj
 
23.09.21
23:42
На другом компе попробовал:
...
Сообщить(Ответ.КодСостояния);
Для каждого Стр Из Ответ.Заголовки Цикл
  Сообщить(Стр.Ключ + " : " + Стр.Значение);
КонецЦикла;

Результат:

200
Via : 1.1 3c1b8c037c66c46a8ac162f1eef5d682.cloudfront.net (CloudFront)
Vary : Accept-Encoding
Content-Security-Policy : default-src https: ;style-src https: 'unsafe-inline'; script-src https: 'unsafe-inline'; img-src https: data:
Server : AmazonS3
X-Amz-Cf-Pop : HEL50-C2
X-XSS-Protection : 1; mode=block
ETag : "9b6f13742cbcda6de279d2bd614b0bd8"
Strict-Transport-Security : max-age=63072000; includeSubdomains; preload
X-Cache : Error from cloudfront
Last-Modified : Thu, 16 Sep 2021 15:10:56 GMT
X-Edge-Origin-Shield-Skipped : 0
Date : Thu, 23 Sep 2021 20:40:34 GMT
X-Amz-Cf-Id : rRpw7Xh_tSQ8ItvnCbn0Vt8QoCXzpzKqdTceuyU1k_NLdMWVBmIJ8A==
X-Content-Type-Options : nosniff
Connection : close
Content-Type : text/html
X-Frame-Options : DENY
Cache-Control : no-cache
Accept-Ranges : bytes
Content-Length : 3876
7 polosov
 
24.09.21
10:10
(5) Это похоже на Auth 2.0
Тебе в ответе приходит страничка, которую надо показать пользователю. Он введет свои данные, выдаст разрешения, а потом ты получишь код вместе с Redirect_Uri для получения токена. Документацию надо.
8 timurhv
 
24.09.21
10:25
А так?

Ответ = Соединение.ВызватьHTTPМетод("POST", HTTPЗапрос);
9 Kassern
 
24.09.21
10:32
с той стороны поддержка, что говорит? Им приходит данные аутентификации?
10 youalex
 
24.09.21
10:35
в заголовке можно кодировку попробовать указать еще(но не факт)

content-type: application/json; charset utf-8
11 zva
 
24.09.21
10:59
X-Cache : Error from cloudfront
Лучше с их поддержкой связаться
https://stackoverflow.com/questions/59160472/how-to-solve-x-cache-error-from-cloudfront-on-spa

Можно еще Postman-ом попробовать запрос сделать, но скорей всего CloudFront криво настроен
12 Sj
 
24.09.21
19:12
спасибо!
Сервер надо было указывать
api-qa.wabi2b.com
AdBlock убивает бесплатный контент. 1Сергей