當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RequestCtx.FormValue方法代碼示例

本文整理匯總了Golang中github.com/valyala/fasthttp.RequestCtx.FormValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang RequestCtx.FormValue方法的具體用法?Golang RequestCtx.FormValue怎麽用?Golang RequestCtx.FormValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/valyala/fasthttp.RequestCtx的用法示例。


在下文中一共展示了RequestCtx.FormValue方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ClientFormFastHandler

// ClientFormFastHandler 客戶端表單信息(基於fasthttp)
func ClientFormFastHandler(ctx *fasthttp.RequestCtx) (clientID, clientSecret string, err error) {
	clientID = string(ctx.FormValue("client_id"))
	clientSecret = string(ctx.FormValue("client_secret"))
	if clientID == "" || clientSecret == "" {
		err = ErrAuthorizationFormInvalid
	}
	return
}
開發者ID:Curtis-ly,項目名稱:oauth2,代碼行數:9,代碼來源:authorize.go

示例2: GetAuthorizeRequest

// GetAuthorizeRequest 獲取授權請求參數
func (fs *FastServer) GetAuthorizeRequest(ctx *fasthttp.RequestCtx) (authReq *AuthorizeRequest, err error) {
	if !ctx.IsGet() {
		err = ErrRequestMethodInvalid
		return
	}
	redirectURI, err := url.QueryUnescape(string(ctx.FormValue("redirect_uri")))
	if err != nil {
		return
	}
	authReq = &AuthorizeRequest{
		Type:        oauth2.ResponseType(string(ctx.FormValue("response_type"))),
		RedirectURI: redirectURI,
		State:       string(ctx.FormValue("state")),
		Scope:       string(ctx.FormValue("scope")),
		ClientID:    string(ctx.FormValue("client_id")),
	}
	if authReq.Type == "" || !fs.checkResponseType(authReq.Type) {
		err = ErrResponseTypeInvalid
	} else if authReq.ClientID == "" {
		err = ErrClientInvalid
	}
	return
}
開發者ID:Curtis-ly,項目名稱:oauth2,代碼行數:24,代碼來源:fastserver.go

示例3: HandleTokenRequest

// HandleTokenRequest 處理令牌請求
func (fs *FastServer) HandleTokenRequest(ctx *fasthttp.RequestCtx) (err error) {
	if !ctx.IsPost() {
		err = ErrRequestMethodInvalid
		return
	}
	gt := oauth2.GrantType(string(ctx.FormValue("grant_type")))
	if gt == "" || !fs.checkGrantType(gt) {
		err = ErrGrantTypeInvalid
		return
	}

	var ti oauth2.TokenInfo
	clientID, clientSecret, err := fs.cfg.Handler.ClientFastHandler(ctx)
	if err != nil {
		return
	}
	tgr := &oauth2.TokenGenerateRequest{
		ClientID:     clientID,
		ClientSecret: clientSecret,
	}

	switch gt {
	case oauth2.AuthorizationCodeCredentials:
		tgr.RedirectURI = string(ctx.FormValue("redirect_uri"))
		tgr.Code = string(ctx.FormValue("code"))
		tgr.IsGenerateRefresh = true
		ti, err = fs.manager.GenerateAccessToken(oauth2.AuthorizationCodeCredentials, tgr)
	case oauth2.PasswordCredentials:
		userID, uerr := fs.cfg.Handler.UserHandler(string(ctx.FormValue("username")), string(ctx.FormValue("password")))
		if uerr != nil {
			err = uerr
			return
		}
		tgr.UserID = userID
		tgr.Scope = string(ctx.FormValue("scope"))
		tgr.IsGenerateRefresh = true
		ti, err = fs.manager.GenerateAccessToken(oauth2.PasswordCredentials, tgr)
	case oauth2.ClientCredentials:
		tgr.Scope = string(ctx.FormValue("scope"))
		ti, err = fs.manager.GenerateAccessToken(oauth2.ClientCredentials, tgr)
	case oauth2.RefreshCredentials:
		tgr.Refresh = string(ctx.FormValue("refresh_token"))
		tgr.Scope = string(ctx.FormValue("scope"))
		if tgr.Scope != "" { // 檢查授權範圍
			rti, rerr := fs.manager.LoadRefreshToken(tgr.Refresh)
			if rerr != nil {
				err = rerr
				return
			} else if rti.GetClientID() != tgr.ClientID {
				err = ErrRefreshInvalid
				return
			} else if verr := fs.cfg.Handler.ScopeHandler(tgr.Scope, rti.GetScope()); verr != nil {
				err = verr
				return
			}
		}
		ti, err = fs.manager.RefreshAccessToken(tgr)
		if err == nil {
			ti.SetRefresh("")
		}
	}

	if err != nil {
		return
	}
	err = fs.ResJSON(ctx, ti)
	return
}
開發者ID:Curtis-ly,項目名稱:oauth2,代碼行數:69,代碼來源:fastserver.go


注:本文中的github.com/valyala/fasthttp.RequestCtx.FormValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。