gocialite icon indicating copy to clipboard operation
gocialite copied to clipboard

Redirecting to original URL

Open jpoles1 opened this issue 6 years ago • 5 comments

Hey, thanks for the great library, really nice to see a passport-like software for Golang.

I'm trying to use the Google authorization scheme, and I'd like to redirect my users to the page from which they started before being required to login. Google forbids any redirect URLs using wildcards and thus I cannot include my source URL in the redirect directly.

I've read that I should be able to include my source URL in the "state" which is returned, but I'm not certain that there's a way to go about doing so using Gocialite functions. Am I missing something? Thanks!

jpoles1 avatar Oct 20 '18 18:10 jpoles1

First of all, thank you!

I can see the issue, unfortunately I'll be busy in the next few weeks, but I hope to find time to figure out how to pass custom values in the state.

I'll keep you updated :)

danilopolani avatar Oct 20 '18 18:10 danilopolani

Excellent, thank you @danilopolani.

If you've got an approach in mind I can do my best to help out!

jpoles1 avatar Oct 21 '18 14:10 jpoles1

@danilopolani any progress on this issue? Happy to help in whatever way I can, particularly if you can set me on the right path!

jpoles1 avatar Dec 06 '18 07:12 jpoles1

@danilopolani any updates on this issue? If you have more info on how you had planned to solve this problem, I can try and work on a fix myself.

jpoles1 avatar Mar 14 '19 13:03 jpoles1

Hello @jpoles1 , sorry for my delay in the answers, unfortunately I'm in a very busy time due to my new work and some personal stuff and I'm unable to steadily follow this project.

Since in Dispatcher.Handler() we do not return the Gocial instance (where we could put the redirect URL), adding it to response would be a breaking change. Nothing impossible, I can create a v2.0 with some other stuff, but requires time.

For the moment what about storing the URL / parameters in a cookie? Not the best solution, but it could work, with Gin you can achieve it with SetCookie.

In the next version I would add a params (name to choose) map which will be a [string]interface{} in the Gocial struct where you can save whatever you want, so when you can handle callback you can do:

// Handle callback and check for errors
user, token, params, err := gocial.Handle(state, code)
if err != nil {
	c.Writer.Write([]byte("Error: " + err.Error()))
	return
}

redirectURL := params["redirect"].(string)

What do you think about it?

danilopolani avatar Mar 26 '19 09:03 danilopolani