context

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

@Author daixk 2025/12/22 15:56:00

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DTokenContext

type DTokenContext struct {
	// contains filtered or unexported fields
}

DTokenContext defines current request context DTokenContext 定义当前请求的 DToken 上下文

func NewContext

func NewContext(reqCtx adapter.RequestContext, mgr *manager.Manager) *DTokenContext

NewContext creates dtoken context NewContext 创建新的 DTokenContext 上下文

func (*DTokenContext) AddPermissions

func (c *DTokenContext) AddPermissions(ctx context.Context, permissions []string) error

AddPermissions adds permissions AddPermissions 为当前用户添加权限

func (*DTokenContext) AddRoles

func (c *DTokenContext) AddRoles(ctx context.Context, roles []string) error

AddRoles adds roles AddRoles 为当前用户添加角色

func (*DTokenContext) CheckLogin

func (c *DTokenContext) CheckLogin(ctx context.Context) error

CheckLogin checks login state with error CheckLogin 检查当前 token 是否已登录并在未登录时返回错误

func (*DTokenContext) Disable

func (c *DTokenContext) Disable(ctx context.Context, duration time.Duration, reason ...string) error

Disable disables current user Disable 封禁当前用户账号指定时长

func (*DTokenContext) GenerateNonce

func (c *DTokenContext) GenerateNonce(ctx context.Context) (string, error)

GenerateNonce generates nonce GenerateNonce 生成新的 nonce

func (*DTokenContext) GetDevice

func (c *DTokenContext) GetDevice(ctx context.Context) (string, error)

GetDevice gets token device GetDevice 获取当前 token 的设备类型

func (*DTokenContext) GetDeviceId

func (c *DTokenContext) GetDeviceId(ctx context.Context) (string, error)

GetDeviceId gets token device id GetDeviceId 获取当前 token 的设备 ID

func (*DTokenContext) GetDisableInfo

func (c *DTokenContext) GetDisableInfo(ctx context.Context) (*manager.DisableInfo, error)

GetDisableInfo gets disable info GetDisableInfo 获取当前用户的封禁信息

func (*DTokenContext) GetDisableTTL

func (c *DTokenContext) GetDisableTTL(ctx context.Context) (int64, error)

GetDisableTTL gets disable ttl GetDisableTTL 获取当前用户的封禁剩余时间

func (*DTokenContext) GetLoginID

func (c *DTokenContext) GetLoginID(ctx context.Context) (string, error)

GetLoginID gets login id by token GetLoginID 获取当前 token 关联的登录 ID

func (*DTokenContext) GetManager

func (c *DTokenContext) GetManager() *manager.Manager

GetManager returns related manager GetManager 获取关联的认证管理器

func (*DTokenContext) GetOnlineTerminalCount

func (c *DTokenContext) GetOnlineTerminalCount(ctx context.Context) (int, error)

GetOnlineTerminalCount gets online terminal count GetOnlineTerminalCount 获取当前用户的在线终端数量

func (*DTokenContext) GetOnlineTerminalCountByDevice

func (c *DTokenContext) GetOnlineTerminalCountByDevice(ctx context.Context, device string) (int, error)

GetOnlineTerminalCountByDevice gets online terminal count by device GetOnlineTerminalCountByDevice 按设备获取当前用户的在线终端数量

func (*DTokenContext) GetOnlineTerminalCountByDeviceAndDeviceId

func (c *DTokenContext) GetOnlineTerminalCountByDeviceAndDeviceId(ctx context.Context, device, deviceId string) (int, error)

GetOnlineTerminalCountByDeviceAndDeviceId gets online terminal count by device and id GetOnlineTerminalCountByDeviceAndDeviceId 按设备和设备 ID 获取当前用户的在线终端数量

func (*DTokenContext) GetPermissions

func (c *DTokenContext) GetPermissions(ctx context.Context) ([]string, error)

GetPermissions gets permission list GetPermissions 获取当前登录用户的权限列表

func (*DTokenContext) GetPermissionsByToken

func (c *DTokenContext) GetPermissionsByToken(ctx context.Context) ([]string, error)

GetPermissionsByToken gets permission list by token GetPermissionsByToken 使用当前 token 获取权限列表

func (*DTokenContext) GetRequestContext

func (c *DTokenContext) GetRequestContext() adapter.RequestContext

GetRequestContext returns raw request context GetRequestContext 获取原始请求上下文

func (*DTokenContext) GetRoles

func (c *DTokenContext) GetRoles(ctx context.Context) ([]string, error)

GetRoles gets role list GetRoles 获取当前登录用户的角色列表

func (*DTokenContext) GetRolesByToken

func (c *DTokenContext) GetRolesByToken(ctx context.Context) ([]string, error)

GetRolesByToken gets role list by token GetRolesByToken 使用当前 token 获取角色列表

func (*DTokenContext) GetSession

func (c *DTokenContext) GetSession(ctx context.Context) (*manager.Session, error)

GetSession gets session by login id GetSession 获取当前登录用户的 Session

func (*DTokenContext) GetSessionByToken

func (c *DTokenContext) GetSessionByToken(ctx context.Context) (*manager.Session, error)

GetSessionByToken gets session by token GetSessionByToken 使用当前 token 获取 Session

func (*DTokenContext) GetTokenCreateTime

func (c *DTokenContext) GetTokenCreateTime(ctx context.Context) (int64, error)

GetTokenCreateTime gets token create time GetTokenCreateTime 获取当前 token 的创建时间

func (*DTokenContext) GetTokenInfo

func (c *DTokenContext) GetTokenInfo(ctx context.Context) (*manager.TokenInfo, error)

GetTokenInfo gets token info GetTokenInfo 获取当前 token 的信息

func (*DTokenContext) GetTokenTTL

func (c *DTokenContext) GetTokenTTL(ctx context.Context) (int64, error)

GetTokenTTL gets token ttl GetTokenTTL 获取当前 token 的剩余有效期

func (*DTokenContext) GetTokenValue

func (c *DTokenContext) GetTokenValue() string

GetTokenValue gets token from current request GetTokenValue 按 Header、Cookie、Body 顺序获取 Token

func (*DTokenContext) GetTokenValueList

func (c *DTokenContext) GetTokenValueList(ctx context.Context, checkAlive ...bool) ([]string, error)

GetTokenValueList gets token list GetTokenValueList 获取当前登录用户的全部 token 列表

func (*DTokenContext) GetTokenValueListByDevice

func (c *DTokenContext) GetTokenValueListByDevice(ctx context.Context, device string, checkAlive ...bool) ([]string, error)

GetTokenValueListByDevice gets token list by device GetTokenValueListByDevice 按设备获取当前用户的 token 列表

func (*DTokenContext) GetTokenValueListByDeviceAndDeviceId

func (c *DTokenContext) GetTokenValueListByDeviceAndDeviceId(ctx context.Context, device, deviceId string, checkAlive ...bool) ([]string, error)

GetTokenValueListByDeviceAndDeviceId gets token list by device and id GetTokenValueListByDeviceAndDeviceId 按设备和设备 ID 获取当前用户的 token 列表

func (*DTokenContext) HasPermission

func (c *DTokenContext) HasPermission(ctx context.Context, permission string) bool

HasPermission checks permission HasPermission 检查当前用户是否拥有指定权限

func (*DTokenContext) HasPermissions

func (c *DTokenContext) HasPermissions(ctx context.Context, permissions []string) bool

HasPermissions checks any permission HasPermissions 检查当前用户是否拥有任意指定权限

func (*DTokenContext) HasPermissionsAnd

func (c *DTokenContext) HasPermissionsAnd(ctx context.Context, permissions []string) bool

HasPermissionsAnd checks all permissions HasPermissionsAnd 检查当前用户是否拥有全部指定权限

func (*DTokenContext) HasRole

func (c *DTokenContext) HasRole(ctx context.Context, role string) bool

HasRole checks role HasRole 检查当前用户是否拥有指定角色

func (*DTokenContext) HasRoles

func (c *DTokenContext) HasRoles(ctx context.Context, roles []string) bool

HasRoles checks any role HasRoles 检查当前用户是否拥有任意指定角色

func (*DTokenContext) HasRolesAnd

func (c *DTokenContext) HasRolesAnd(ctx context.Context, roles []string) bool

HasRolesAnd checks all roles HasRolesAnd 检查当前用户是否拥有全部指定角色

func (*DTokenContext) IsDisable

func (c *DTokenContext) IsDisable(ctx context.Context) bool

IsDisable checks disable state IsDisable 检查当前用户是否被封禁

func (*DTokenContext) IsLogin

func (c *DTokenContext) IsLogin(ctx context.Context) bool

IsLogin checks login state IsLogin 检查当前 token 是否已登录

func (*DTokenContext) IsNonceValid

func (c *DTokenContext) IsNonceValid(ctx context.Context, nonce string) bool

IsNonceValid checks nonce validity IsNonceValid 检查 nonce 是否有效且不消费

func (*DTokenContext) Kickout

func (c *DTokenContext) Kickout(ctx context.Context) error

Kickout kicks out current token Kickout 踢出当前 token

func (*DTokenContext) KickoutByDevice

func (c *DTokenContext) KickoutByDevice(ctx context.Context, device string) error

KickoutByDevice kicks out current user by device KickoutByDevice 按设备踢出当前用户

func (*DTokenContext) KickoutByDeviceAndDeviceId

func (c *DTokenContext) KickoutByDeviceAndDeviceId(ctx context.Context, deviceAndDeviceId ...string) error

KickoutByDeviceAndDeviceId kicks out current user by device and id KickoutByDeviceAndDeviceId 按设备和设备 ID 踢出当前用户

func (*DTokenContext) KickoutByLoginID

func (c *DTokenContext) KickoutByLoginID(ctx context.Context) error

KickoutByLoginID kicks out all terminals KickoutByLoginID 踢出当前用户的所有终端

func (*DTokenContext) LoginByToken

func (c *DTokenContext) LoginByToken(ctx context.Context) error

LoginByToken logs in by current token LoginByToken 使用当前 token 登录

func (*DTokenContext) Logout

func (c *DTokenContext) Logout(ctx context.Context) error

Logout logs out current token Logout 登出当前 token

func (*DTokenContext) LogoutByDevice

func (c *DTokenContext) LogoutByDevice(ctx context.Context, device string) error

LogoutByDevice logs out current user by device LogoutByDevice 按设备登出当前用户

func (*DTokenContext) LogoutByDeviceAndDeviceId

func (c *DTokenContext) LogoutByDeviceAndDeviceId(ctx context.Context, deviceAndDeviceId ...string) error

LogoutByDeviceAndDeviceId logs out current user by device and id LogoutByDeviceAndDeviceId 按设备和设备 ID 登出当前用户

func (*DTokenContext) LogoutByLoginID

func (c *DTokenContext) LogoutByLoginID(ctx context.Context) error

LogoutByLoginID logs out all terminals LogoutByLoginID 登出当前用户的所有终端

func (*DTokenContext) RemovePermissions

func (c *DTokenContext) RemovePermissions(ctx context.Context, permissions []string) error

RemovePermissions removes permissions RemovePermissions 从当前用户移除权限

func (*DTokenContext) RemoveRoles

func (c *DTokenContext) RemoveRoles(ctx context.Context, roles []string) error

RemoveRoles removes roles RemoveRoles 从当前用户移除角色

func (*DTokenContext) Replace

func (c *DTokenContext) Replace(ctx context.Context) error

Replace replaces current token Replace 顶替当前 token

func (*DTokenContext) ReplaceByDevice

func (c *DTokenContext) ReplaceByDevice(ctx context.Context, device string) error

ReplaceByDevice replaces current user by device ReplaceByDevice 按设备顶替当前用户

func (*DTokenContext) ReplaceByDeviceAndDeviceId

func (c *DTokenContext) ReplaceByDeviceAndDeviceId(ctx context.Context, deviceAndDeviceId ...string) error

ReplaceByDeviceAndDeviceId replaces current user by device and id ReplaceByDeviceAndDeviceId 按设备和设备 ID 顶替当前用户

func (*DTokenContext) ReplaceByLoginID

func (c *DTokenContext) ReplaceByLoginID(ctx context.Context) error

ReplaceByLoginID replaces all terminals ReplaceByLoginID 顶替当前用户的所有终端

func (*DTokenContext) RevokeOAuth2Token

func (c *DTokenContext) RevokeOAuth2Token(ctx context.Context, accessToken string) error

RevokeOAuth2Token revokes oauth2 token RevokeOAuth2Token 撤销 OAuth2 访问令牌及其刷新令牌

func (*DTokenContext) Untie

func (c *DTokenContext) Untie(ctx context.Context) error

Untie removes disable state Untie 解封当前用户账号

func (*DTokenContext) ValidateOAuth2AccessToken

func (c *DTokenContext) ValidateOAuth2AccessToken(ctx context.Context, accessToken string) bool

ValidateOAuth2AccessToken validates access token ValidateOAuth2AccessToken 验证 OAuth2 访问令牌

func (*DTokenContext) ValidateOAuth2AccessTokenAndGetInfo

func (c *DTokenContext) ValidateOAuth2AccessTokenAndGetInfo(ctx context.Context, accessToken string) (*oauth2.AccessToken, error)

ValidateOAuth2AccessTokenAndGetInfo validates access token and gets info ValidateOAuth2AccessTokenAndGetInfo 验证 OAuth2 访问令牌并获取信息

func (*DTokenContext) VerifyAndConsumeNonce

func (c *DTokenContext) VerifyAndConsumeNonce(ctx context.Context, nonce string) error

VerifyAndConsumeNonce verifies nonce with error VerifyAndConsumeNonce 验证并消费 nonce 且在无效时返回错误

func (*DTokenContext) VerifyNonce

func (c *DTokenContext) VerifyNonce(ctx context.Context, nonce string) bool

VerifyNonce verifies and consumes nonce VerifyNonce 验证并消费 nonce

Jump to

Keyboard shortcuts

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