7
0
Go to file
2020-08-06 17:29:29 +08:00
sdk delete sign value 2020-08-06 17:29:29 +08:00
services/jedi init project 2020-08-06 16:04:44 +08:00
.gitignore init project 2020-08-03 20:48:58 +08:00
README.md delete sign value 2020-08-06 17:29:29 +08:00

gaore-common-sdk-go

目录架构

├── README.md
├── sdk
│   ├── auth                    `认证类`
│   ├── client.go               `客户端主入口类`
│   ├── config.go
│   ├── requests                `请求类`
│   ├── responses               `响应类`
│   └── utils                   `工具类`
└── services
    └── jedi

服务端认证调用事例

调用 auth.UnSign 方法,提供*http.Request请求实例,以及signer.Signer 签名器(签名器需要包括凭据) 即可完成整个验签过程

package main

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
	"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth"
	"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
	"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/signers"
	
)

func init() {
	// 过滤器
    beego.InsertFilter("/api/*", beego.BeforeRouter, func(context *context.Context) {
        httpRequest := context.Request
		err := auth.UnSign(httpRequest, signers.NewAccessKeySigner(&credentials.AccessKeyCredential{
			AccessKeyId:     "aaaaaa",
			AccessKeySecret: "bbbbbb",
			AccessKeyFrom:   context.Input.Param("access_from"),
		}))

		if err != nil {
			resp := response.NewJsonByDefaultFailed()
			resp.Msg = err.Error()
			resp.Code =  10086

			var (
				hasIndent   = beego.BConfig.RunMode != beego.PROD
			)
			context.Output.Status = 500
			context.Output.JSON(resp, hasIndent,  false)
		}
	})
}