如何使用OAuth2和Microsoft登录名和HTTP请求使用用户名/密码登录 [英] How to login with username/password using OAuth2 and microsoft login and HTTP request

查看:471
本文介绍了如何使用OAuth2和Microsoft登录名和HTTP请求使用用户名/密码登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己回答这个问题,是为了使我们的开发人员更轻松,更快乐地找到这些信息,因为我个人发现有很多信息需要经过.

I am self answering this to make life easier and more joyful for us developers to find this information, as I personally found that there was lots of info to go through.

如何使用OAuth2和Microsoft登录名使用用户名/密码(最终用户凭据)登录 https://login.microsoftonline.com/ {app-id}/oauth2/token

How to login with username/password (end-user credentials) using OAuth2 and Microsoft login https://login.microsoftonline.com/{app-id}/oauth2/token

推荐答案

Microsoft不建议为最终用户传递用户名/密码信息.这就是为什么他们不为此发布指南.出于安全原因,他们希望您使用重定向到其登录页面.使用 https://login.microsoftonline.com/ {tenant-id}/oauth2/authorize到达那里.

Microsoft does not recommend passing username/password information for endusers. That is why they dont post guides for this. For security reason they want you to use the redirection to their login page. Use https://login.microsoftonline.com/{tenant-id}/oauth2/authorize to get there.

但是使用其oauth2 rest api可以并且非常容易做到这一点.

However it is possible and very easy to do this using their oauth2 rest api.

创建一个http请求以

Create an http request to

base url: https://login.microsoftonline.com/{tenant-id}/oauth2/token
{tenant-id} //obtained from AzureAD config section

在正文部分使用以下请求参数

Use the following request parameters in the body section

grant_type = password //read up on the other grant types, they are all useful, client_credentials and authorization_code
client_id = {client-id}//obtained from the application section in AzureAD
client_secret = {client-secret}//obtained from the application section in AzureAD
resource = https://graph.microsoft.com //there is also the api https://graph.windows.net, use the latest and best one
username = {enduser-username} //example rofler@domain.onmicrosoft.com
password = {enduser-password} //example Hs782f8a

成功的响应应包括access_token和refresh_token

A successful response should include the access_token and refresh_token

经过2016年测试

推荐链接

  • Postman
  • Microsoft Graph
  • Windows Graph

这篇关于如何使用OAuth2和Microsoft登录名和HTTP请求使用用户名/密码登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆