I implemented a one-page application with the implementation of token-based authentication using MVC 6, OpenId and Aurelia front end framework. In Startup.cs, the Configure method looks like this:
The authentication provider is defined as follows:
public class AuthenticationProvider : OpenIdConnectServerProvider { public override Task ValidateClientAuthentication(ValidateClientAuthenticationContext context) { if (context.ClientId == "AureliaNetAuthApp") {
This defines the marker endpoint that can be reached on url /connect/token .
So, to request a token from the client side, here is the javascript code taken from AuthService in authSvc.js:
login(username, password) { var baseUrl = yourBaseUrl; var data = "client_id=" + yourAppClientId + "&grant_type=password" + "&username=" + username + "&password=" + password + "&resource=" + encodeURIComponent(baseUrl); return this.http.fetch(baseUrl + 'connect/token', { method: 'post', body : data }); }
The full source can be seen here:
https://github.com/alexandre-spieser/AureliaAspNetCoreAuth
Hope this helps,
Best
Alex
source share