[英]Authentication with Azure using OAuth2 for an ionic mobile app
I have been trying to retrieve the token from Azure AD by posting in the username and password using the HTTP angular service. 我一直在尝试使用HTTP角度服务通过在用户名和密码中发布从Azure AD检索令牌。 Unfortunately, I always get this error: 不幸的是,我总是得到这个错误:
Failed to load resource: the server responded with a status of 400 (Bad Request) It complains the following: " The request body must contain the following parameter: 'grant_type' " 无法加载资源:服务器的状态为400(错误请求),它抱怨以下内容:“ 请求正文必须包含以下参数:'grant_type' ”
Does anyone have any idea what this is happening? 有谁知道这是怎么回事?
This is my login controller and I have set up my Azure AD already. 这是我的登录控制器,并且我已经设置了Azure AD。
function access() { 函数access(){
var username = vm.username.trim();
var password = vm.password.trim();
requestAccessToken(username, password);
}
function requestAccessToken(username, password){ 函数requestAccessToken(用户名,密码){
var base_url = 'https://login.windows.net';
var client_id = "35d16a1c-3f01-402a-9346-ee13b0aa2ba0";
var params = '?grant_type=password&client_id=' + client_id + '&username=' + username + '&password=' + password;
var path = "/4397b89d-d9d7-4d27-9cac-f7ae0ff0d880/oauth2/token";
//var path = "/common/oauth2/token"; we have tried this one too
var url = base_url + path + params;
$http.post(url).success(getAccessTokenSuccess).error(getAccessTokenFailure);
}
function getAccessTokenSuccess(data, status, header, config) {
console.log('data: ', data);
}
function getAccessTokenFailure(data, status, header, config) {
console.log('data: ', data);
}
看起来您需要在请求正文中发送grant_url
(这意味着HTTP请求可能是POST),而不是作为查询参数,这就是您正在执行的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.