authorization

package
v0.12.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 11 Imported by: 0

README

获取访问token

安装

go get github.com/hanguangbaihuo/sparrow_cloud_go/

注意

必须配置环境变量:
SC_MANAGE_SVC
SC_MANAGE_API
配置下面环境为true跳过缓存
SC_SKIP_TOKEN_CACHE

获取app_token

import (
    "github.com/hanguangbaihuo/sparrow_cloud_go/authorization"
)

func main() {
    // 注意修改函数参数为自己服务的名称和服务注册密钥
    token, err := authorization.GetAppToken("YourServiceName", "ServiceSecret")
    if err != nil {
        // handle error
    }
}

获取user_token

import (
    "github.com/hanguangbaihuo/sparrow_cloud_go/authorization"
)

func main() {
    // 注意修改函数参数为自己服务的名称和服务注册密钥,和用户ID
    token, err := authorization.GetUserToken("YourServiceName", "ServiceSecret", "user_id")
    if err != nil {
        // handle error
    }
}

token使用

//直接将获取到的token赋值给restclient包中函数的kwargs参数中的token,例如:
token, err := authorization.GetAppToken("YourServiceName", "ServiceSecret")
if err != nil {
    // handle error
}
kwargs := map[string]interface{}{"token":token}
res, err := restclient.Post(serviceAddr, apiPath, data, kwargs)
if err != nil {
// do something
}
fmt.Println(string(res.Body), res.Code)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAppToken

func GetAppToken(svcName string, svcSecret string) (string, error)

func GetUserToken

func GetUserToken(svcName string, svcSecret string, userID string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL