Exemplo n.º 1
0
func handleOAuth2Callback(f *oauth2.Config, s session.Store, w http.ResponseWriter, r *http.Request) {
	next := extractPath(r.URL.Query().Get("state"))
	code := r.URL.Query().Get("code")
	t, err := f.Exchange(oauth2.NoContext, code)
	if err != nil {
		// Pass the error message, or allow dev to provide its own
		// error handler.
		http.Redirect(w, r, PathError, codeRedirect)
		return
	}
	// Store the credentials in the session.
	val, _ := json.Marshal(t)
	s.Set(keyToken, val)
	http.Redirect(w, r, next, codeRedirect)
}
Exemplo n.º 2
0
func handleOAuth2Callback(ctx *macaron.Context, s session.Store, opt *Options) {
	next := extractPath(ctx.Query("state"))
	code := ctx.Query("code")
	t, err := opt.NewTransportFromCode(code)
	if err != nil {
		// Pass the error message, or allow dev to provide its own
		// error handler.
		println(err.Error())
		ctx.Redirect(PathError)
		return
	}
	// Store the credentials in the session.
	val, _ := json.Marshal(t.Token())
	s.Set(KEY_TOKEN, val)
	ctx.Redirect(next)
}
Exemplo n.º 3
0
func (u *User) Login(sess session.Store) {
	sess.Set("uid", u.Id)
}
Exemplo n.º 4
0
func mySessionHandler(sess session.Store) string {
	sess.Set("session", "session middleware")
	return sess.Get("session").(string)
}