// the user will eventually be redirected back to your redirect URL
// typically you'll have a handler set up like the following:
the user will eventually be redirected back to your redirect URL
typically you'll have a handler set up like the following.
// the user will eventually be redirected back to your redirect URL // typically you ' ll have a handler set up like the following :
func authCallbackHandler(w http.ResponseWriter, r *http.Request) {
	stateCookie, err := r.Cookie("spin-it.session")
	if err != nil {
		log.Error("failed to get state cookie for oauth2: ", "err", err.Error())
		http.Error(w, "server error", http.StatusInternalServerError)
		return
	}
	token, err := spotifyclient.Token(stateCookie.Value, r)
	if err != nil {
		log.Error("Couldn't get token", "err", err.Error())
		http.Error(w, "Couldn't get token", http.StatusNotFound)
		return
	}
	c := spotifyclient.NewClient(token)
	client = &c
	user, err := client.CurrentUser()
	if err != nil {
		log.Fatal(err)
	}
	log.Info("You are logged in as:", user.ID)
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	json.NewEncoder(w).Encode(authResponse{*token})
}
func authCallbackHandler ( w http . ResponseWriter , r * http . Request ) { stateCookie , err := r . Cookie ( " " ) if err != nil { log . Error ( " " , " " , err . Error ( ) ) http . Error ( w , " " , http . StatusInternalServerError ) return } token , err := spotifyclient . Token ( stateCookie . Value , r ) if err != nil { log . Error ( " " , " " , err . Error ( ) ) http . Error ( w , " " , http . StatusNotFound ) return } c := spotifyclient . NewClient ( token ) client = & c user , err := client . CurrentUser ( ) if err != nil { log . Fatal ( err ) } log . Info ( " " , user . ID ) w . Header ( ) . Set ( " " , " " ) w . WriteHeader ( http . StatusOK ) json . NewEncoder ( w ) . Encode ( authResponse { * token } ) }
the user will eventually be redirected back to your redirect URL
typically you'll have a handler set up like the following.
the user will eventually be redirected back to your redirect URL typically you ' ll have a handler set up like the following .
// Get oauth2 tokens // use the same state string here that you used to generate the URL // create a client using the specified token // the client can now be used to make authenticated requests // use the client to make calls that require authorization