简体   繁体   English

通过用户名和密码从Azure广告获取AccessToken

[英]Getting AccessToken from Azure Ad via UserName & Password

I have a Native Client registered in our Azure AD. 我在我们的Azure AD中注册了本机客户端。

When i'm using 当我使用

var ar = _context.AcquireToken(resource, clientId, returnUri);

It opens the Prompt for Username and Password. 它会打开“提示输入用户名和密码”。 If I enter them correctly I get a valid AccessToken and everything is fine. 如果输入正确,我将获得有效的AccessToken,一切都很好。

When I'm now trying to enter the credentials in code, via UserCrendtial: 当我现在尝试通过UserCrendtial在代码中输入凭据时:

var credential = new UserCredential("username", "password");

var ar = _context.AcquireToken(resource, clientId, credential);

But both resulting in an Error when I'm trying it with the directly entered Credentials. 但是当我使用直接输入的凭据尝试尝试时,都会导致错误。

AADSTS65001: No permission to access user information is configured for '4915f024-blah-blah-blah-f580ab5b0487' application, or it is expired or revoked. AADSTS65001:没有为“ 4915f024-blah-blah-blah-f580ab5b0487”应用程序配置访问用户信息的权限,或者该应用程序已过期或被吊销。

I have tried the normal (string, string) and the (string, SecureString) overload of the UserCredential. 我已经尝试了UserCredential的常规(string, string)(string, SecureString)重载。 I have tried it with the exact same combination of username & password, which I have entered in the Prompt, of the first overload from AcquireToken. 我尝试使用与我在提示中输入的用户名和密码完全相同的组合来尝试此操作,这是AcquireToken的第一个重载。

I have also tried to give the Application in Azure all the Delegated Permissions: 我还尝试赋予Azure中的应用程序所有委派的权限:

  • Read directory data 读取目录数据
  • Read and write directory data 读写目录数据
  • Access your organization's directory 访问您组织的目录

And added Windows Azure Service Management API Application with Permission: 并添加了具有权限的Windows Azure服务管理API应用程序:

  • Access Azure Service Management 访问Azure服务管理

Nothing helped. 没有任何帮助。

As a sidenote, the Application in the Azure has permissions to a SharePoint O365 Tenant. 附带说明,Azure中的应用程序具有SharePoint O365租户的权限。 To Read and Write ListItems I don't know if this is relevant. 读写ListItems我不知道这是否相关。 The Resource i'm passing through is the SharePoint Adress. 我正在传递的资源是SharePoint地址。

I don't need any user access over the Graph Api to the Azure. 我不需要任何用户通过Graph Api访问Azure。 I only need that AccessToken to access our SharePoint Online. 我只需要该AccessToken即可访问我们的SharePoint Online。

Edit: 编辑:

Architecture: 建筑:

在此处输入图片说明

Description: 描述:

We have a Web Api Project which handles the User Authorization, Load Balancing etc. This Web Api Project, will be queried by either Native Dekstop Clients or Hybrid HTML5 & Javascript Mobile Device Apps. 我们有一个处理用户授权,负载平衡等的Web Api项目。此Web Api项目将由本机Dekstop客户端或混合HTML5和Javascript移动设备应用程序查询。

The Web Api Project needs to Read, Create, Update & Delete Data from our SharePoint O365 Tenant. Web Api项目需要从SharePoint O365租户读取,创建,更新和删除数据。 So this where I need the AccessToken to init a ClientContext or send i via a rest response. 所以这是我需要AccessToken初始化ClientContext或通过rest响应发送给我的地方。

Since the Web Api handles the User authorization, there is an endpoint for users to login already and in this endpoint I want to acquire the Token. 由于Web Api处理用户授权,因此存在一个可供用户登录的端点,并且我想在该端点中获取令牌。 That's why I want it to be silent, because the "flexbile browser popup" is already there. 这就是为什么我希望它保持沉默,因为“灵活的浏览器弹出窗口”已经存在。

Maybe I don't need in this scenario the Token acquiring with Username / Password, but then I don't know how to configure the Azure App right to work with all the different native client's. 在这种情况下,也许我不需要使用用户名/密码来获取令牌,但是我不知道如何配置Azure应用权限以与所有不同的本机客户端一起使用。

not sure if it's your case but you can use : 不确定是否是您的情况,但可以使用:

  • built in auth (setting 'on' in webapp options; then create express app or/and then chose advanced mode with same apps ids); 内置身份验证(在webapp选项中设置为“ on”;然后创建快速应用或/,然后选择具有相同应用ID的高级模式);
  • then add AD native client app; 然后添加AD本机客户端应用程序;
  • login to old classic portal there select native app and in config add access to you express/advacsed web app; 登录到旧的经典门户网站,在其中选择本机应用程序,并在配置中添加对您快速/高级Web应用程序的访问权限;
  • after that you will able login in browser; 之后,您将可以登录浏览器; and with adal lib will able login to access you api from mobile devices; 并使用adal lib可以登录以从移动设备访问您的api;

for more see ms docs and samples; 有关更多信息,请参见ms docs和示例;

The direct use of username and password has important limitations, please make sure you are not stumbling on any of the ones listed in http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/ . 用户名和密码的直接使用有重要限制,请确保您不要绊倒http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to中列出的任何用户名和密码-authenticate-users-via-usernamepassword / Also note, nothing that requires displaying a user consent screen (as all the permissions you described will) or specific disambiguation steps (like trying to use a guest user from X to access a resource protected by tenant Y) will work. 还要注意,不需要显示用户同意屏幕(如您所描述的所有权限)或特定的消歧步骤(例如尝试从X使用来宾用户访问受租户Y保护的资源)的任何操作都不会起作用。 What is your scenario? 您的情况是什么? Any specific reason for which you want to use username/password instead of the more flexible browser popup? 您要使用用户名/密码而不是更灵活的浏览器弹出窗口的任何特定原因?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure AD 认证来自用户名和密码 - Azure AD authentication from username and password 通过Azure Functions对Azure AD中的用户进行身份验证(验证用户名和密码) - Authenticate User In Azure AD (validate username & password) via Azure Functions 允许用户通过 Azure AD 用户名和密码登录 - Allow user to sign in by Azure AD username and password 使用用户名/密码连接到Azure AD - Connect to Azure AD using username/password 如何验证 Azure AD 中的用户名和密码? - How do I validate a username and password in Azure AD? WebAPI使用用户名和密码对Azure AD进行非交互式身份验证 - WebAPI Non-interactive authenticating to Azure AD using username & password Azure AD 认证,带用户名和密码,也有 MFA - Azure AD authentication with Username and Password and also have MFA 如何仅使用 Azure Ad 用户名和密码连接和访问 Azure Datalake Gen1 存储 - c# - How to connect and access Azure Datalake Gen1 storage using Azure Ad username and password only - c# 从用户名和密码输入中获取主键 - Getting the primary key from a username and password entry Azure AD 使用用户名/密码从 API 进行身份验证 - 没有 UI,有示例吗? - Azure AD Authenticate from API with username/pw - no UI, is there an example?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM