Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Interactive authentication in .net core 2.0 console application on windows #885

Closed
jannikbuschke opened this issue Oct 31, 2017 · 6 comments

Comments

@jannikbuschke
Copy link

I'm trying to prompt a user for credentials in a net core 2.0 console application running on windows but didn't find any ressources that show me how to do it properly.

This is what I tried:

var authority = "https://login.microsoftonline.com/<mytenantname>";
var ctx = new AuthenticationContext(authority);
var appId = "<myappid>";
var resourceId = "https://graph.microsoft.com";
await ctx.AcquireTokenAsync(resourceId, appId, new Uri("http://localhost"), new PlatformParameters());

However I get a NotImplemented exception.

Is this scenario supported?

@jmprieur
Copy link
Contributor

jmprieur commented Nov 1, 2017

.NET Core does not provide UI (contrary to .NET Framework 4.5, UWP etc ...). Therefore any interactive flow is not supported. the reason is that Azure AD returns directly some HTML to be presented in a Web browser, and .NET Core does not provide any.

@jmprieur jmprieur closed this as completed Nov 1, 2017
@jannikbuschke
Copy link
Author

I see. Thanks for clarifying

@liroforum
Copy link

Hi, I am having the same issue. Is there an alternative way?

@jmprieur
Copy link
Contributor

Yes. We strongly advise that you use MSAL.NET, which does support interactive flow with .NET Core.

See https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-acquire-token

@liroforum
Copy link

Sorry I was a bit carried away. So my is a web app(aspnetcore) and not a desktop app and I get the above when I use with ConfidentialClientApplication. So from your link I found the below.

https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-api-call-api-call-api

But it does not have a code for the interactive one. How would you implement interactive token aquisition in a aspnetcore application? When I use the below code it complains it is not possible in aspnetcore.

@jmprieur
Copy link
Contributor

If this is a Web app, that's the link you need to use, @liroforum
https://docs.microsoft.com/azure/active-directory/develop/scenario-web-app-call-api-overview
but you will probably want to read https://docs.microsoft.com/azure/active-directory/develop/scenario-web-app-sign-user-overview first.

In a nutshell, in a Web App, the sign-in part is done by ASP.NET Core. The token acquisition by MSAL. We also have an incremental tutorial https://github.com/Azure-Samples/ms-identity-aspnetcore-webapp-tutorial

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants