Closed gaetandezeiraud closed 3 years ago
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.
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!
The /google
route is automatically created by the router.oAuth
call. You should be good to go!
OK, thanks for the details! I'll be back soon with a merger request for Keycloak support.
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 messageUser currently not authenticated
. But, I want to redirect the user to the Google Login Page, for authentification.But, I can not access to
authURL
inGoogleRouter
for set this value inImperialMiddleware(redirect: <#T##String?#>)
. How can I do it?Thanks.