capesean / openiddict-test Goto Github PK
View Code? Open in Web Editor NEWExample ASP.NET V5 project that issues & validates JWT tokens
Example ASP.NET V5 project that issues & validates JWT tokens
Looks like you're missing 'await' in your Startup.cs
Should be:
public async void Configure(IApplicationBuilder app, IDatabaseInitializer databaseInitializer)
and
await databaseInitializer.Seed();
Would it be easy to convert this example to Angular 2 and use the Angular2-jwt with minimal efforts?
Getting :
{"error":"invalid_grant","error_description":"Invalid credentials."}
For some reason User.Roles
is empty when it reaches the controller and throws a 403 for role based authorization.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IDatabaseInitializer databaseInitializer, UserManager<ApplicationUser> userManager)
{
...
app.UseOpenIddictCore(...);
app.UseJwtBearerAuthentication(new JwtBearerOptions() {...});
app.Use(async (context, next) =>
{
var user = await userManager.GetUserAsync(context.User);
//-------> user.Roles.Count = 1
await next.Invoke();
});
app.UseMvc(...);
...
}
But, in the controller:
[Authorize]
public class MeController : Controller
{
private CoreModelsDbContext _context;
private readonly UserManager<ApplicationUser> _userManager;
public MeController(CoreModelsDbContext context, UserManager<ApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
[Route("api/v1/me"), HttpGet]
public async Task<IActionResult> Get()
{
var user = await _userManager.GetUserAsync(User);
//-------> user.Roles.Count = 0
return user == null ? Ok("No user / not logged in") : Ok(user);
}
}
Any idea how this would happen?
After applying migrations, starting up the server and pressing the "Get Token" button,
the server responds with a HTTP 500.
According to the logs, instead of using the ApplicationRole the IdentityRole is being used.
I have not been able to find a solution yet. The full log is as follows:
System.InvalidOperationException:Cannot create a DbSet for 'IdentityRole' because this type is not included in the model for the context.
at Microsoft.EntityFrameworkCore.DbContext.SetTEntity
at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore4.get_Roles() at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore
4.d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.Identity.UserManager
1.d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at OpenIddict.OpenIddictUserManager
1.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at OpenIddict.Infrastructure.OpenIddictProvider
5.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.<HandleRequestAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware
1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()
I fetched token which is also saved in local storage, but can't authorize for API call. Suppose I have to manually realize auth logic writing something to Startup.cs?
Hi, I'm trying to create a WebAPI project based on this example, by creating a new ASP.NET Core Web API app and following the code. Anyway, it seems that the OpenIddictUser
class is no more present in the current version of Openiddict which gets restored: the version is beta1 0467 at the time of writing.
Hi,
I have downloaded the sample source code from the GitHub. Also, I have checked that I have latest dnx version in my machine. See attached screenshot.
But still when I try to run this solution its giving following errors.
I think its not supporting dnx 4.5.1 or any other problem I have can you please suggest what I am doing wrong.
Hi! Started to explore your library and have, probably, dumb architectural question.
We're using .net core server for authorization and REST API and node.js server for web socket communication (via socket.io).
Currently, PasswordFlow is used and auth part of the code is mostly same as in your sample
We're able to validate token in REST API endpoints on .Net core instance but we also want to use the same token for web sockets.
Is there a way to validate it on node.js server without making a request to .Net core instance?
In your corresponding article you wrote that you are planning to use your setup with Angular. Do have any recommandations for a client library that handles the oidc stuff (login, logout, refresh token in particular) or are you planning to implement that yourself?
got this error with newest bits (visual studio update 3 including a kb patch from today) on a fresh git clone:
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=At least one OAuth2/OpenID Connect flow must be enabled.
Source=OpenIddict.Core
StackTrace:
at Microsoft.AspNetCore.Builder.OpenIddictExtensions.UseOpenIddict(IApplicationBuilder app)
at openiddicttest.Startup.Configure(IApplicationBuilder app, IDatabaseInitializer databaseInitializer)
Looks like OpenIddictTokenManager has changed to only take a Token type. Also, the overriden method "CreateIdentityAsync" no longer exists
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.