Giter VIP home page Giter VIP logo

vapor-firebase-jwt-middleware's People

Contributors

barisatamer avatar liamdon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vapor-firebase-jwt-middleware's Issues

Is it worth documenting "injecting a request's authenticated user" in the README?

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! ☺️

Update the middleware to modern Swift concurrency

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.