Conflict between System.IdentityModel.Tokens and Microsoft.IdentityModel.Tokens

System.IdentityModel.Tokens.Jwt version 5.0.0.0 depends on Microsoft.IdentityModel.Tokens. You need to use SigningCredentials in the Microsoft.IdentityModel.Tokens namespace. Example: using System; using System.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Text; public void voidGenereToken() { const string sec = “401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1”; var now = DateTime.UtcNow; var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.Default.GetBytes(sec)); var signingCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials( securityKey, SecurityAlgorithms.HmacSha256Signature); var header = new JwtHeader(signingCredentials); var … Read more

Preserve cookies / localStorage session across tests in Cypress

To update this thread, there is already a better solution available for preserving cookies (by @bkucera); but now there is a workaround available now to save and restore local storage between the tests (in case needed). I recently faced this issue; and found this solution working. This solution is by using helper commands and consuming … Read more

Laravel: What is “remember_token” in the “users” DB table?

No. It’s not supposed to be used to authenticate. It’s used by the framework to help against Remember Me cookie hijacking. The value is refreshed upon login and logout. If a cookie is hijacked by a malicious person, logging out makes the hijacked cookie useless since it doesn’t match anymore. Refer to this documentation: https://laravel.com/docs/4.2/upgrade#upgrade-4.1.29

What’s the best way to save jwt tokens in flutter apps?

You probably don’t want to store sensitive data in shared preferences. Instead you might want to look into a plugin like this: https://pub.dartlang.org/packages/flutter_secure_storage import ‘package:flutter_secure_storage/flutter_secure_storage.dart’; // Create storage final storage = new FlutterSecureStorage(); // Write value await storage.write(key: ‘jwt’, value: token);

JWT Token authentication, expired tokens still working, .net core Web Api

I believe this has to do with ClockSkew in JwtBearerOptions. Change to TimeSpan.Zero as I think the default is set to 5 minutes (not 100% sure though). I have posted some sample code below that is to be placed in Startup.cs => Configure. app.UseJwtBearerAuthentication(new JwtBearerOptions() { AuthenticationScheme = “Jwt”, AutomaticAuthenticate = true, AutomaticChallenge = true, … Read more

C# unsupported grant type when calling web api

The default implementation of OAuthAuthorizationServerHandler only accepts form encoding (i.e. application/x-www-form-urlencoded) and not JSON encoding (application/JSON). Your request’s ContentType should be application/x-www-form-urlencoded and pass the data in the body as: grant_type=password&username=Alice&password=password123 i.e. not in JSON format. The chrome example above works because it is not passing data as JSON. You only need this for getting … Read more

How to get a Token from a Lucene TokenStream?

Yeah, it’s a little convoluted (compared to the good ol’ way), but this should do it: TokenStream tokenStream = analyzer.tokenStream(fieldName, reader); OffsetAttribute offsetAttribute = tokenStream.getAttribute(OffsetAttribute.class); TermAttribute termAttribute = tokenStream.getAttribute(TermAttribute.class); while (tokenStream.incrementToken()) { int startOffset = offsetAttribute.startOffset(); int endOffset = offsetAttribute.endOffset(); String term = termAttribute.term(); } Edit: The new way According to Donotello, TermAttribute has been … Read more

Is setting Roles in JWT a best practice?

The official JWT site explicitly mentions “authorization” (in contrast to “authentication”) as a usecase for JWTs: When should you use JSON Web Tokens? Authorization: This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources … Read more