Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion Closure Not Invoked When Using Google Auth #84

Closed
rwbutler opened this issue Jul 15, 2021 · 1 comment
Closed

Completion Closure Not Invoked When Using Google Auth #84

rwbutler opened this issue Jul 15, 2021 · 1 comment

Comments

@rwbutler
Copy link

rwbutler commented Jul 15, 2021

At the moment, I'm trying to use Imperial to allow users to sign in to me web app using Google Auth. I've set up my code as follows (see below). The issue I'm experiencing at the moment is that processGoogleLogin is never fired. If I navigate to /google then I do see the OAuth page and on logging in using my Google account I am redirected to /authenticated which is correct but I never received an access token back it would seem and completion closure never appears to fire. Is there a piece of the set up that I am missing perhaps?

Thanks in advance 🙏

routes.swift

let imperialController = ImperialController(sessionsMiddleware: app.sessions.middleware)
try appRoutes.register(collection: imperialController)

ImperialController.swift

class ImperialController {
    private let sessionsMiddleware: Middleware
    
    init(sessionsMiddleware: Middleware) {
        self.sessionsMiddleware = sessionsMiddleware
    }
    
    func processGoogleLogin(request: Request, token: String) throws -> EventLoopFuture<ResponseEncodable> {
        print(token)
        return request.eventLoop.future(request.redirect(to: "/"))
    }
}

extension ImperialController: RouteCollection {
    func boot(routes: RoutesBuilder) throws {
        let group = routes.grouped(sessionsMiddleware)
        try group.oAuth(
            from: Google.self,
            authenticate: "google",
            authenticateCallback: nil,
            callback: "http://localhost:8080/authenticated",
            scope: ["profile", "email"],
            completion: processGoogleLogin
        )
    }
}
@rwbutler
Copy link
Author

I've realised that this issue is a manifestation of #43 - so long as route groups aren't used then this will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant