Question
How do we use a media token with ASP.NET 5 using a username and password stream? For our scenario, we want the user to register and log in using AJAX calls without the need for an external login.
To do this, we need to have an authorization server endpoint. In previous versions of ASP.NET, we would follow these steps and then run with the address ourdomain.com/Token .
// Configure the application for OAuth based flow PublicClientId = "self"; OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14) };
In the current version of ASP.NET, however, this does not work. We tried to figure out a new approach. the aspnet / identity example on GitHub, for example, configures Facebook, Google and Twitter authentication, but does not display the endpoint of the OAuth external authorization server, unless that means AddDefaultTokenProviders() , in which case we are wondering what the URL will be provider.
Study
We learned from reading the source here that we can add "bearer authentication middleware" to the HTTP pipeline by calling IAppBuilder.UseOAuthBearerAuthentication in our Startup class. This is a good start, although we are still not sure how to set the token endpoint. It did not help:
public void Configure(IApplicationBuilder app) { app.UseOAuthBearerAuthentication(options => { options.MetadataAddress = "meta"; });
When we go to ourdomain.com/meta we just get our worldwide welcome page.
Further studies have shown that we can also use the IAppBuilder.UseOAuthAuthentication extension IAppBuilder.UseOAuthAuthentication and that it accepts the OAuthAuthenticationOptions parameter. This parameter has the TokenEndpoint property. Therefore, although we are not sure what we are doing, we tried it, which, of course, did not work.
public void Configure(IApplicationBuilder app) { app.UseOAuthAuthentication("What is this?", options => { options.TokenEndpoint = "/token"; options.AuthorizationEndpoint = "/oauth"; options.ClientId = "What is this?"; options.ClientSecret = "What is this?"; options.SignInScheme = "What is this?"; options.AutomaticAuthentication = true; });
In other words, there is no mistake when switching to ourdomain.com/Token , we will return our global welcome page again.