Do I have to store tokens in cookies or localstorage or session?

This answer is based on the stateless approach and therefore it doesn’t talk about the traditional session management You have asked two altogether different questions: Shopping cart – which is more related to business functionality OAuth 2 & JWT – which is related to security and authentication As an user of an ecommerce website, I’d … Read more

Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?

UPDATE July 21st, 2012 Google Analytics API V3 now supports OAuth2 tokens returned by a .p12-signed JWT request. That is, we can now use the Analytics API w/ service accounts. Currently pulling 4 years of day-by-day metrics, just for the hell of it. Here’s a quick ‘n’ dirty step-by-step: Go to the Google API Console … Read more

Authenticating socket io connections using JWT

It doesn’t matter if the token was created on another server. You can still verify it if you have the right secret key and algorithm. Implementation with jsonwebtoken module client const {token} = sessionStorage; const socket = io.connect(‘http://localhost:3000’, { query: {token} }); Server const io = require(‘socket.io’)(); const jwt = require(‘jsonwebtoken’); io.use(function(socket, next){ if (socket.handshake.query … Read more

Verifying JWT signed with the RS256 algorithm using public key in C#

Thanks to jwilleke, I have got a solution. To verify the RS256 signature of a JWT, it is needed to use the RSAPKCS1SignatureDeformatter class and its VerifySignature method. Here is the exact code for my sample data: string tokenStr = “eyJraWQiOiIxZTlnZGs3IiwiYWxnIjoiUlMyNTYifQ.ewogImlzcyI6ICJodHRwOi8vc2VydmVyLmV4YW1wbGUuY29tIiwKICJzdWIiOiAiMjQ4Mjg5NzYxMDAxIiwKICJhdWQiOiAiczZCaGRSa3F0MyIsCiAibm9uY2UiOiAibi0wUzZfV3pBMk1qIiwKICJleHAiOiAxMzExMjgxOTcwLAogImlhdCI6IDEzMTEyODA5NzAsCiAiY19oYXNoIjogIkxEa3RLZG9RYWszUGswY25YeENsdEEiCn0.XW6uhdrkBgcGx6zVIrCiROpWURs-4goO1sKA4m9jhJIImiGg5muPUcNegx6sSv43c5DSn37sxCRrDZZm4ZPBKKgtYASMcE20SDgvYJdJS0cyuFw7Ijp_7WnIjcrl6B5cmoM6ylCvsLMwkoQAxVublMwH10oAxjzD6NEFsu9nipkszWhsPePf_rM4eMpkmCbTzume-fzZIi5VjdWGGEmzTg32h3jiex-r5WTHbj-u5HL7u_KP3rmbdYNzlzd1xWRYTUs4E8nOTgzAUwvwXkIQhOh5TPcSMBYy6X3E7-_gr9Ue6n4ND7hTFhtjYs3cjNKIA08qm5cpVYFMFMG6PkhzLQ”; string[] tokenParts = tokenStr.Split(‘.’); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.ImportParameters( new RSAParameters() { Modulus … Read more

How Spring Security Filter Chain works

The Spring security filter chain is a very complex and flexible engine. Key filters in the chain are (in the order) SecurityContextPersistenceFilter (restores Authentication from JSESSIONID) UsernamePasswordAuthenticationFilter (performs authentication) ExceptionTranslationFilter (catch security exceptions from FilterSecurityInterceptor) FilterSecurityInterceptor (may throw authentication and authorization exceptions) Looking at the current stable release 4.2.1 documentation, section 13.3 Filter Ordering you … Read more

How to decode JWT Token?

I found the solution, I just forgot to Cast the result: var stream = “[encoded jwt]”; var handler = new JwtSecurityTokenHandler(); var jsonToken = handler.ReadToken(stream); var tokenS = jsonToken as JwtSecurityToken; Or, without the cast: var token = “[encoded jwt]”; var handler = new JwtSecurityTokenHandler(); var jwtSecurityToken = handler.ReadJwtToken(token); I can get Claims using: var … Read more

Where to save a JWT in a browser-based application and how to use it

Choosing the storage is more about trade-offs than trying to find a definitive best choice. Let’s go through a few options: Option 1 – Web Storage (localStorage or sessionStorage) Pros The browser will not automatically include anything from Web storage into HTTP requests making it not vulnerable to CSRF Can only be accessed by Javascript … Read more