简体   繁体   English

使用OAuth2对离子移动应用程序进行Azure身份验证

[英]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.

相关问题 使用前端(混合移动应用程序)上的ionic / angularjs和后端的expressjs + passportjs + mongodb实现linkedin oauth2 - Implementing linkedin oauth2 with ionic/angularjs on frontend (hybrid mobile app) and expressjs+passportjs+mongodb on backend 在Ionic应用程序中访问经Jhipster Oauth2认证的REST API - Access jhipster Oauth2 authenticated REST API in ionic app AngularJS和Oauth2提供程序的身份验证? - AngularJS and authentication to an Oauth2 Provider? 带有ADFS的Angular / Ionic移动应用程序上的OAUTH授权代码授予 - OAUTH Authorization Code Grant on Angular/Ionic Mobile App with ADFS 使用Google oauth2登录角度全栈默认应用 - logging into angular fullstack default app using google oauth2 使用Passport for Ionic App进行角度认证 - Angular authentication using Passport for Ionic App Spring OAuth2 和 AngularJS 应用程序中的身份验证/授权 - Spring OAuth2 and authentication/authorizatiuon in AngularJS application 处理oauth2身份验证的角度方式 - Handling oauth2 authentication the angular way 通过oAuth2功能进行AngularJS身份验证/授权 - AngularJS Authentication / Authorization via oAuth2 functionality Azure移动服务身份验证可以在网页中运行,而不是在Cordova应用程序中? - Azure mobile service authentication works in web page not in Cordova app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM