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

How can I get Google authURL? #38

Closed
gaetandezeiraud opened this issue Apr 12, 2019 · 4 comments
Closed

How can I get Google authURL? #38

gaetandezeiraud opened this issue Apr 12, 2019 · 4 comments
Labels

Comments

@gaetandezeiraud
Copy link
Contributor

Hi,
I have setup like indicated in the Google guide.
When I'm adding a route in an protected route (with ImperialMiddleware) , I get following message User currently not authenticated. But, I want to redirect the user to the Google Login Page, for authentification.

But, I can not access to authURL in GoogleRouter for set this value in ImperialMiddleware(redirect: <#T##String?#>). How can I do it?

Thanks.

@calebkleveter
Copy link
Member

The redirect parameter in the ImperialMiddleware initializer is the path to redirect the client to if they are not authenticated.

I have outlined how to actually authenticate the user in the Google auth guide.

Basically you register the auth route like this:

try router.oAuth(from: Google.self, authenticate: "google", callback: "http://localhost:8080/google-complete")

Then the client can go to the /google route, which will redirect them to Google for sign-in.

@gaetandezeiraud
Copy link
Contributor Author

Ok I see, thanks for your awnser.
But, I need to create the /google route? Because by default, I have just the message in log and not redirection. My code is:

try router.oAuth(from: Google.self, authenticate: "google", callback: "http://localhost:8080/google-complete", scope: ["https://www.googleapis.com/auth/cloud-platform"]) { (request, token) in
 print(token)
 return request.future(request.redirect(to: "/"))
 }

And

let protected = router.grouped(ImperialMiddleware())
protected.get("hello") { req in
        return "Hello, world!"
}

And I get {"error":true,"reason":"User currently not authenticated"} but no redirection.

If I need to create this route, how I can get the authURL available in GoogleRouter.swift with clientID, scope, etc?

Thanks you, for the project and your quick response!

@calebkleveter
Copy link
Member

The /google route is automatically created by the router.oAuth call. You should be good to go!

@gaetandezeiraud
Copy link
Contributor Author

OK, thanks for the details!
I'll be back soon with a merger request for Keycloak support.

@0xTim 0xTim closed this as completed Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants