// NewAuthorizeHandler returns a http.HandlerFunc which will set the Token of // the given oauth.Transport and send a struct{} on the donech on success. func NewAuthorizeHandler(transport *oauth.Transport, donech chan<- struct{}) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { token, err := transport.Exchange(r.FormValue("code")) if err != nil { http.Error(w, fmt.Sprintf("error exchanging code: %v", err), http.StatusBadRequest) return } transport.Token = token // The Transport now has a valid Token. donech <- struct{}{} } }