I want to get a token from ADAL to authenticate a specific server call.
I tried using this code:
var authorityUrl = string.Format(@"https://login.microsoftonline.com/{0}/oauth2/token", AadInstance);
var context = new AuthenticationContext(authorityUrl);
var credential = new ClientCredential(ClientId, ClientSecret);
var authenticationResult = context.AcquireTokenAsync(RemoteClientId, credential).Result;
return authenticationResult.AccessToken;
But I get this in the logs:
AcquireTokenHandlerBase.cs: === Token Acquisition started:
Authority: https://login.microsoftonline.com/f9e55202-63c0-4821-9fc7-e38eb5bc3a08/oauth2/token/
Resource: 80d147c1-0b9a-48e0-8a62-1dc82890e98e
ClientId: cab18d6f-3edc-446b-a071-45b28b192f0b
CacheType: null
Authentication Target: Client
TokenCache.cs: Looking up cache for a token...
TokenCache.cs: No matching token was found in the cache
AcquireTokenHandlerBase.cs: System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.IdentityModel.Clients.ActiveDirectory.BrokerHelper.get_CanInvokeBroker () [0x0000c] in <f671779d8b3b49399b31bf519785e86e>:0
at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase+<RunAsync>d__55.MoveNext () [0x00389] in <e4081d9da4634689910019c82c03f3e7>:0
I have no idea what could be wrong with this, since the same code works as expected in an Android application, while it does not work in the iOS version.
vrwim source
share