How do I form a oauth2 password-grant request using webwrite [grant_type = "password" ]

조회 수: 35 (최근 30일)
How do I request an access token using Oauth2 with the grant_type = "password"
I have tried:
client_id = 'client_id_FILL';%'YOUR CLIENT ID ';
client_secret = 'client_secret_FILL';%'YOUR CLIENT SECRET ';
url = 'https://your_url/connect/token';
username = 'usernameFILL';
password='passwFILL';
scope = 'scope-FILL';
headerFields = {'Content-type' 'application/x-www-form-urlencoded';'charset' 'UTF-8'};
options = weboptions('HeaderFields', headerFields);
response = webwrite(url,...
'client_id', client_id,...
'client_secret', client_secret,...
'grant_type','password',...
'scope',scope,...
'username',username,...
'password',password,...
options);
resulting in
Error using readContentFromWebService (line 46)
The server returned the status 400 with message "Bad Request" in response to the request to URL
Problem solved:
the above code is working. In my case, the error originated from server side, where there was an issue with the username and password.

채택된 답변

Steven Remington
Steven Remington 2019년 1월 18일
I would look into the link below which forms an oauth2 for google api:
The above link shows how the request is formed to construct a weboptions object.
  댓글 수: 1
Robin Lataire
Robin Lataire 2019년 1월 25일
Thanks for the input. I used your above reference to write the code. Meanwhile, the error was solved. The above code is working. In my case, the error originated from server side, where there was an issue with the username and password.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by