我在Finatra上有一个Scala休息服务,并希望使用Azure Active Directory验证访问我的休息服务的用户。
目前,我可以做一个卷曲来获取访问令牌:
curl -s -X POST https://login.microsoftonline.com/tenant id/oauth2/token -d grant_type=password -d username=$username -d password=$pass -d resource=$resID -d client_id=$id -d client_secret=$key
但它要求用户将其密码作为安全问题的参数传递。
有没有办法使用Azure AD验证用户并输入密码(我很确定这是不可能的)或要求他登录?
答案 0 :(得分:0)
建议不要使用您的用户和密码登录Azure帐户。您最好创建服务主体以登录Azure帐户。请参阅此链接:Use portal to create an Azure Active Directory application and service principal that can access resources。
此外,您可以使用Azure CLI 2.0来创建它。
az ad sp create-for-rbac --name {appId} --password "{strong password}"
示例:
az ad sp create-for-rbac --name shuiexample --password "Password012!!"
你可以得到如下结果:
{
"appId": "bca24913-026d-4020-b9f1-add600bf9045",
"displayName": "shuiexample1234",
"name": "http://shuiexample1234",
"password": "*******",
"tenant": "*******"
}
使用服务主体登录。
APPID="bca24913-026d-4020-b9f1-add600bf9045"
PASSWORD="******"
TENANTID="*******"
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=$APPID&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret=$PASSWORD&grant_type=client_credentials' 'https://login.microsoftonline.com/$TENANTID/oauth2/token'