tomsteele/dmv — pull request #4 by bgentry (2014-04-07 13:46:05+00:00)
Title: Add RedirectFunc to OAuth2Options

I wanted to be able to redirect to a relative path because the web server may not always know which hostnames it's serving. It may also not know whether it's serving over SSL or not. For example, I'd love to be able to run my server locally, then push the same code to Heroku and have it work (without making unnecessary extra config changes).

I added a new field, `RedirectFunc`, to `OAuth2Options`. `RedirectFunc` is a `func(*http.Request) string` that allows the user to generate a redirect URL based on the request. This enables redirection to relative paths, without necessarily knowing the hostname or URL scheme in advance.

`RedirectRelativeFunc()` is a convience function that returns functions suitable for use as a RedirectFunc. The funcs it returns redirect requests to a relative path, maintaining the URL scheme, port, and hostname of the callback request.

I also added a test for this functionality (and the non-func `RedirectURL`).