Tag: adal

通过MVC Web App中的ViewModel调用Graph API

我正在尝试使用Graph API来创建我自己的Web应用程序导航栏的“用户配置文件”部分。 为此,我对我的UserProfile控制器的GetUser操作进行了AJAX调用: $.ajax({ type: “GET”, url: “@Url.Action(“GetUser”, “UserProfile”, null)”, dataType: “json”, success: function (data, status, xhr) { console.log(“in AJAX”); $(“.img-circle, .user-image”).attr(“src”, data.Picture); $(“#user-menu-expanded”).text(data.User.DisplayName + ” – ” + data.User.JobTitle); $(“#user-menu-spinner”).remove(); console.log(data); }, error: function (ex) { console.log(ex); } }); 控制器将我的UserProfileViewModel作为Json返回,我用它来替换上面的元素,如我的AJAX成功函数所示。 UserProfile控制器: public JsonResult GetUser() { var model = new UserProfileViewModel(); return Json(model, JsonRequestBehavior.AllowGet); } […]

在C#REST服务中validationADAL JWT令牌

我有一个Web应用程序,它使用ADAL库通过Azure Active Directory进行身份validation。 此Web应用程序通过将ADAL标记字符串作为参数传递来调用C#REST服务。 在我的REST服务中,我想validation此令牌。 如果令牌有效,则服务将执行操作。 我搜索了很多但是找不到在我的rest服务中validationJWT令牌的方法。 你能帮帮我吗?

如何同步等待’AuthenticationContext.AcquireTokenAsync()’?

首先,我不确定这是否重要,但由于@ Simon Mourier在他回答中提到的原因,我正在使用ADAL的EXPERIMENTAL版本, 这个 。 在下面的代码中,我想同步检索AuthenticationResult ,因此,我将等待AcquireTokenAsync方法以同步方式完成身份validation的AcquireTokenAsync 。 这是因为在授权完成后应该设置一个布尔标志( isAuthorized = true ),但是tg需要以同步的方式发生,因为如果没有,那么我可以调用该类的其他方法,这将引发一个空引用,因为对AcquireTokenAsync的调用没有完成,因此对象为null。 以下代码不起作用,该方法永远不会返回,因为对AcquireTokenAsync方法的调用似乎无限期地冻结了该线程。 C#(由于在线翻译,可能是错误的语法): public void Authorize() { // Use the ‘Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory’ Nuget package for auth. this.authContext = new AuthenticationContext(this.authUrl, this.cache); this.authResult = this.authContext.AcquireTokenAsync({ “https://outlook.office.com/mail.readwrite” }, null, this.clientIdB, this.redirectUriB, new PlatformParameters(PromptBehavior.Auto, this.windowHandleB)).Result; // Use the ‘Microsoft.Office365.OutlookServices-V2.0’ Nuget package from now on. this.client = new […]

即使管理员已经同意,也会触发ADAL用户同意

我创建了一个使用Azure Active Directory进行身份validation的Web API。 它使用多租户AAD。 为了测试它,我还创建了一个控制台应用程序,它使用ADAL库对AAD进行身份validation,以便我可以访问我的API。 在主要的AAD租户中,一切运作良好,因为我不需要授予任何东西。 但是当从第二个租户访问应用程序时,我首先触发管理员同意流程(添加prompt=admin_consent )。 但是当我再次退出并打开应用程序时,如果我尝试使用没有管理员权限的用户登录AAD,它会尝试打开用户同意并且失败(因为用户无权允许访问AAD)。 如果我已经给予管理员同意,那么用户是否应该同意? 测试应用程序的代码是: using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Security.Authentication; using System.Threading.Tasks; using System.Web; using Microsoft.IdentityModel.Clients.ActiveDirectory; using Newtonsoft.Json; namespace TestConsole { internal class Program { private const string _commonAuthority = “https://login.microsoftonline.com/common/”; private static void Main(string[] args) { ConsoleKeyInfo kinfo = Console.ReadKey(true); AuthenticationContext ac […]

ADAL – AcquireTokenSilentAsync失败(Azure Active Directory身份validation库)

我编写了一个新的应用程序来通过其余的API访问办公室数据,因此我想使用新的身份validation模型(V2.0端点) v2.0 endpoit有什么不同 我可以通过电话获得令牌 private static string[] scopes = { “https://outlook.office.com/mail.read”, “https://outlook.office.com/calendars.read” }; public async Task SignIn() { … SNIP Uri authUri = await authContext.GetAuthorizationRequestUrlAsync(scopes, null, clientId, redirectUri, new UserIdentifier(“contoso@foo”, UserIdentifierType.RequiredDisplayableId), null); return Redirect(authUri.ToString()); } authContext.AcquireTokenByAuthorizationCodeAsync(authCode, redirectUri, credential, scopes) 问题是第二次调用 public async Task SignIn() { … SNIP var authResult = authContext.AcquireTokenSilentAsync(scopes, clientId, new UserIdentifier(“contoso@foo.ch”, UserIdentifierType.RequiredDisplayableId)) […]

使用http post请求,使用Graph API在Azure Active Directory(B2C)中创建新用户

我以前使用Active Directory身份validation库(ADAL)以编程方式添加用户,但现在我需要定义“signInNames”(=用户电子邮件),这似乎不可能与ADAL(请告诉我,如果我错了) 。 现在,我正在尝试使用HTTP POST以编程方式添加新用户(本地帐户),遵循MSDN上的文档 。 //Get access token (using ADAL) var authenticationContext = new AuthenticationContext(AuthString, false); var clientCred = new ClientCredential(ClientId, ClientSecret); var authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, clientCred); var token = authenticationResult.Result.AccessToken; //HTTP POST CODE const string mail = “new@email.com”; // Create a new user object. var user = new CustomUser { accountEnabled = true, […]

使用AAD对Azure API App进行身份validation时出现401错误

我有一个API应用程序,与网关主机一起工作正常,现在网关主机已被弃用我正在尝试遵循迁移指南 。 我使用2.8.1 SDK重新部署了我的服务,可以使用AAD或Microsoft帐户使用浏览器登录服务,并使用Swagger测试服务。 但是,我正在尝试让客户端使用ClientId和Secret访问该服务。 代码能够从AAD获取访问令牌,但每当我尝试访问其中一个服务资源时,我总是会收到401错误。 当我调试服务时,我在日志中看到以下内容: Microsoft.Azure.AppService.Authentication Verbose: 0 : Received request: GET https://[myService].azurewebsites.net/api/[myResource] Microsoft.Azure.AppService.Authentication Warning: 0 : JWT validation failed: IDX10214: Audience validation failed. Audiences: ‘https://[myService].azurewebsites.net/’. Did not match: validationParameters.ValidAudience: ‘[AAD ClientId]’ or validationParameters.ValidAudiences: ‘http://[myService].azurewebsites.net’. Microsoft.Azure.AppService.Authentication Information: 0 : Sending response: 401.71 Unauthorized The thread 0x3b00 has exited with code 0 (0x0). 似乎问题是提供请求的受众是https,但validParameters.ValidAudiences集合仅包含http。 […]

ADAL .Net Core nuget包不支持UserPasswordCredential

在ADAL.Net 3.x中,UserPasswordCredential在2.x的UserCredential之上引入。 但同一个UserPasswordCredential在同一个nuget包下的.Net Core中没有公开? UserCredential类只有一个属性UserName namespace Microsoft.IdentityModel.Clients.ActiveDirectory { // // Summary: // Credential used for integrated authentication on domain-joined machines. public class UserCredential { // // Summary: // Constructor to create user credential. Using this constructor would imply integrated // authentication with logged in user and it can only be used in domain joined scenarios. […]

使用ADAL.js获取令牌对Azure移动服务应用进行身份validation

我正在尝试针对Azure移动服务应用validationHTML应用。 安装程序 两个应用程序都使用AAD作为身份validation后端,因此两个应用程序都在Active Directory中注册了一个应用程序: Azure移动服务应用: 按照https://azure.microsoft.com/en-gb/documentation/articles/mobile-services-how-to-register-active-directory-authentication/中的说明进行配置 我编辑了清单以启用客户端流程 为“Windows Azure Active Directory”启用“对其他应用程序的权限”下的“单点登录和读取用户配置文件” HTML应用: 在“对其他应用程序的权限”中,我添加了具有委派权限“访问权限”的Azure移动服务应用程序 Azure移动服务使用.NET后端,我在其中包含并配置了NuGet包“Microsoft Azure移动服务.NET后端安全扩展”,如https://azure.microsoft.com/en-gb/documentation/articles/中所述。 移动服务- DOTNET -后端窗口电话-GET-开始用户/ HTML应用程序使用ADAL.JS和Angular: adalAuthenticationServiceProvider.init( { // Config to specify endpoints and similar for your app clientId: “”, redirectUri: “”, endpoints: { ”: ‘https://ampapp.azure-mobile.net/’ } }, $httpProvider ); 此设置按预期工作,我打开我的HTML应用程序,对Azure AD进行身份validation,重定向到我的应用程序并且我已登录。此外,当我尝试访问我的Azure移动服务时,我看到Adal.js注入持有者令牌。 问题 Azure移动服务不接受承载令牌 – 我获得401未经授权。 我不知道为什么,但Azure移动服务使用它自己的身份validation标头 – 但没关系。 MSDN为Azure移动服务定义了一个所谓的“客户端定向登录操作”: “通过使用已从身份提供商处获得的身份令牌,从Microsoft Azure […]

如何使用ADAL,NetStandard和Azure AD在没有提示CRM Dynamics Online Web服务的情况下进行身份validation

我目前正在尝试创建一个Xamarin应用程序,以便从Dynamics 365在线实例中获取一些信息。 使用AD进行身份validation并访问CRM API的代码将在NetStandard(v1.6)库中逐出。 我使用以下NuGets: Microsoft.IdentityModel.Clients.ActiveDirectory(3.13.9) NETStandard.Library(1.6.1) 我按照以下教程将AD与我的Dynamics实例链接: https : //nishantrana.me/2016/11/13/register-a-dynamics-365-app-with-azure-active-directory/ 这是我的ActiveDirectory助手: public static class ADHelper { public async static Task GetAuthAsync(Uri uri, ClientCredential creditential) { AuthenticationParameters ap = await AuthenticationParameters.CreateFromResourceUrlAsync(uri); String authorityUrl = ap.Authority; String resourceUrl = ap.Resource; AuthenticationResult result = null; AuthenticationContext authContext = new AuthenticationContext(authorityUrl, false); result = await authContext.AcquireTokenAsync(resourceUrl, creditential); return […]