如何使用OAuth2和microsoft登录和HTTP请求使用用户名/密码登录

问题描述 投票:2回答:1

我自己回答这个问题,让我们的开发人员能够更轻松,更快乐地找到这些信息,因为我个人发现有很多信息可以通过。

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

azure login oauth active-directory oauth-2.0
1个回答
11
投票

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

然而,使用他们的oauth2 rest api可以并且非常容易地做到这一点。

创建一个http请求

base url: https://login.microsoftonline.com/{tenant-id}/oauth2/token
{tenant-id} //obtained from AzureAD config 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 [email protected]
password = {enduser-password} //example Hs782f8a

成功的响应应包括access_token和refresh_token

2016年测试

推荐链接

© www.soinside.com 2019 - 2024. All rights reserved.