coauth

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 2 Imported by: 2

README

coauth

介绍

分布式令牌系统简称 coauth。 coauth 系统用来为 API 服务端、移动端、其它类型客户端提供安全访问服务。

依赖

使用 esync 实现初始化锁,防止重复初始化。

安装

go get -u gitee.com/shishshinedone/coauth

使用

1.初始化
默认初始化
auth := coauth.NewCoauth(
    "http://0.0.0.0:0000", 
    "username", 
    "password",
)
err := auth.Init()
if err != nil {
    panic(err)
}
  • 生成客户端模式、可读可写、不超时、推荐版本的coauth
带参数初始化 - 客户端授权模式
auth := coauth.NewCoauth(
    "http://0.0.0.0:0000", 
    "username", 
    "password",
    coauth.WithMode(coauth.ModeClient),        
    coauth.WithScope(coauth.ScopeReadWrite),   
    coauth.WithTimeout(15*time.Second)         
    coauth.WithVersion(coauth.VersionOriginal)
)
err := auth.Init()
if err != nil {
    panic(err)
}
  • coauth.WithMode 指定模式, 默认即为客户端授权模式
  • coauth.WithScope 指定权限范围, 默认可读可写
  • coauth.WithTimeout 指定连接超时时间, 默认不超时
  • coauth.WithVersion 指定版本号, 当前仅有一个版本且为默认值
带参数初始化 - 密码授权模式
auth := coauth.NewCoauth(
    "http://0.0.0.0:0000", 
    "username", 
    "password",
    coauth.WithMode(coauth.ModePassword),
    coauth.WithGrantUsername("grant-username"), 
    coauth.WithGrantPassword("grant-password"), 
    coauth.WithScope(coauth.ScopeReadWrite), 
    coauth.WithTimeout(15*time.Second)         
    coauth.WithVersion(coauth.VersionOriginal)
)
err := auth.Init()
if err != nil {
    panic(err)
}
  • coauth.WithMode 指定模式, 设置为密码授权模式
  • coauth.WithGrantUsername 密码授权模式必填, 密码授权模式用户名
  • coauth.WithGrantPassword 密码授权模式必填, 密码授权模式密码
  • coauth.WithScope 指定权限范围, 默认可读可写
  • coauth.WithTimeout 指定连接超时时间, 默认不超时
  • coauth.WithVersion 指定版本号, 当前仅有一个版本且为默认值
2.获取Key
auth.GetKey()
  • Key 实际为 username (非grant-username)
3.获取Token
auth.GetToken()

提示

与clouds等模块配套使用时,可不调用auth.Init(),clouds内部会调用auth.Init()。 此外,auth.Init()可重入,多次调用也不会重复初始化。

TODO

1.令牌信息探测
  • 没有使用场景, 暂不实现

Documentation

Index

Constants

View Source
const (
	ModeClient   mode = coauth_core.ModeClient
	ModePassword mode = coauth_core.ModePassword
)
View Source
const (
	ScopeRead      scope = coauth_core.ScopeRead
	ScopeReadWrite scope = coauth_core.ScopeReadWrite
)
View Source
const (
	VersionOriginal version = coauth_core.VersionOriginal
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Coauth added in v0.0.6

type Coauth coauth_core.Coauth

func NewCoauth

func NewCoauth(addr, username, password string, optionArray ...Option) Coauth

type Option

type Option func(o *coauth_core.Options)

func WithGrantPassword

func WithGrantPassword(value string) Option

GrantTypePassword模式有效

func WithGrantUsername

func WithGrantUsername(value string) Option

GrantTypePassword模式有效

func WithMode

func WithMode(value mode) Option

func WithScope

func WithScope(value scope) Option

func WithTimeout

func WithTimeout(value time.Duration) Option

func WithVersion

func WithVersion(value version) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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