naftulikay / rocket-oauth-jwt-demo Goto Github PK
View Code? Open in Web Editor NEWDemo for a Rocket OAuth-to-JWT Login Web Application
License: Other
Demo for a Rocket OAuth-to-JWT Login Web Application
License: Other
In #1, we completed the login process by verifying the JWT token returned from Google.
Next, we need to issue our own JWT token and verify requests using that to complete the login flow. Ideally, we'd use asymmetric signing/verification, but for now we can start with HMAC SHA-256 with a symmetric key. Simply generate and return a JWT token from the key in the /oauth/success
response, then use this token to make an authenticated request to a static API endpoint, e.g. /api/hello
.
Presently, as of #1, we simply fetch the OAuth certificates in JSON form at the start of our service and never refresh them:
rocket-oauth-jwt-demo/src/lib.rs
Lines 215 to 235 in 209c031
The certificates are in a simple HashMap<String, String>
format in JSON at https://www.googleapis.com/oauth2/v1/certs.
Expires
header which we can use to determine when to refresh the token.tokio::time::sleep_until
can be used with a single task to refresh the token before the resource expires.left_right
as a concurrency primitive to implement lock-free reading of certificates for the very infrequent writes that will occur.With this implemented, we can have a HTTP service that lives forever, updating the certificates whenever Google tells us that we should with a max refresh duration.
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.