barisatamer / vapor-firebase-jwt-middleware Goto Github PK
View Code? Open in Web Editor NEWVapor 4 Middleware for verifying Firebase ID tokens
Vapor 4 Middleware for verifying Firebase ID tokens
Hey @barisatamer,
I hope all is well. As Vapor 4 is new and I am coming from a NodeJS/Go background, I spent the better part of a day figuring out how to get basic Firebase authentication working. After reading through the source code of this package, I was able to isolate my user authentication needs with the following implementation:
struct User: Authenticatable {
var name: String
}
struct FirebaseJWTAuthenticator: RequestAuthenticator {
func authenticate(request: Request) -> EventLoopFuture<Void> {
return request.firebaseJwt.verify().flatMap { (payload) -> EventLoopFuture<Void> in
request.auth.login(User(name: payload.userID))
return request.eventLoop.makeSucceededFuture(())
}
}
}
Note its similarity to your packages:
open class FirebaseJWTMiddleware: Middleware {
public init() {}
public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
request.firebaseJwt.verify().transform(to: next.respond(to: request))
}
}
As I was able to register the User as Authenticatable, I was able to guard a group of routes as follows and utilize the user's information in a controller:
app.group(FirebaseJWTAuthenticator(), User.guardMiddleware()) { app in
app.get("helloworld") { (req: Request) throws -> EventLoopFuture<User> in
let user = try req.auth.require(User.self)
return req.eventLoop.makeSucceededFuture(user)
}
}
Is this worth documenting to clarify the scope of this package in-relationship to other authentication considerations (injecting a user)? This could improve the developer experience as it would have helped me hours ago!
I found this package, and want to use it in my Vapor project. Unfortunately it can't be added to Package.swift, because I use the new JWT "5.0.0-beta.2" and JWTKit "5.0.0-beta.2.1". I tried to see if I could translate the project myself, but that turned out to be over my head. Is it possible that you could update the package?
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.