authok

package module
v0.0.0-...-d9c2254 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 2 Imported by: 0

README

Authok 的 Go SDK

GoDoc Go Report Card Release License Build Status Codecov FOSSA Status

📚 文档 • 🚀 入门指南 • 💬 反馈


文档

  • Godoc - 请查看 Go SDK 文档以了解详情。
  • 管理API 文档 - 请浏览 Authok 管理 API,并了解与此 SDK 交互的方式。
  • 文档站点 — 请浏览我们的文档站点并了解更多关于 Authok 的信息。
  • 示例 - 关于 SDK 使用的更多示例。

入门指南

要求

该库遵循与Go相同的支持政策。当前正在积极支持最近的两个重要版发布的Go版本,如果有兼容性问题将会进行修复。尽管旧版本的Go也许仍能运行,但我们将不会积极测试和修复这些旧版本与库的兼容性问题。

  • Go 1.19+

安装步骤

go get github.com/authok/authok-go

使用说明

package main

import (
	"log"

	"github.com/authok/authok-go"
	"github.com/authok/authok-go/management"
)

func main() {
	// 从您的 Authok 应用 Dashboard 获取这些信息。
  // 应用程序需要授权为Machine To Machine才能请求Authok Management API的访问令牌,
  // 具有所需的权限(作用域)。
	domain := "example.authok.com"
	clientID := "EXAMPLE_16L9d34h0qe4NVE6SaHxZEid"
	clientSecret := "EXAMPLE_XSQGmnt8JdXs23407hrK6XXXXXXX"

	// 使用域名、客户端ID和客户端秘钥初始化一个新的客户端。
  // 或者,您可以指定一个访问令牌:
  // `management.WithStaticToken("token")`
	authokAPI, err := management.New(
		domain,
		management.WithClientCredentials(clientID, clientSecret),
	)
	if err != nil {
		log.Fatalf("failed to initialize the authok management API client: %+v", err)
	}

// 现在我们可以与Authok Management API进行交互了。
// 例如:创建一个新的 client。
	client := &management.Client{
		Name:        authok.String("My Client"),
		Description: authok.String("Client created through the Go SDK"),
	}

  // 传入的 client 将会从响应中获取实例数据。
  // 这意味着,在此请求之后,我们可同一个 client 对象中访问 clientID。
	err = authokAPI.Client.Create(client)
	if err != nil {
		log.Fatalf("failed to create a new client: %+v", err)
	}

  // 使用getter函数来安全地访问字段,避免由空指针引起的宕机问题。
	log.Printf(
		"Created an authok client successfully. The ID is: %q",
		client.GetClientID(),
	)
}

频率限制

Authok 管理API对所有API客户端都实施速率限制。当达到限制时,SDK将在后台处理它, 当限制被解除时,SDK将自动重新尝试API请求。

注意事项 SDK 不能防止 http.StatusTooManyRequests 错误,它将根据 X-Rate-Limit-Reset 头部信息的剩余秒数进行限速控制。

反馈

贡献信息

我们欢迎您对该仓库进行反馈及贡献!在开始之前,请先阅读以下内容:

发起问题

如需提供反馈或报告错误,请在我们的问题跟踪器上发起一个问题。

漏洞报告

请不要在公共的 Github 问题跟踪器上报告安全漏洞。责任披露计划详细说明了披露安全问题的过程。


Authok Logo

Authok 是一款易于实现、适应性强的身份验证和授权平台。
了解更多请访问 为什么选择 Authok?

该项目基于 MIT 许可证获得授权。详细信息请参阅 LICENSE 文件。

Documentation

Overview

Package authok provides a client for using the Authok Management API.

Usage

import (
    github.com/authok/authok-go
    github.com/authok/authok-go/management
)

Initialize a new client using a domain, client ID and secret.

m, err := management.New(domain, management.WithClientCredentials(id, secret))
if err != nil {
    // handle err
}

Or using a static token.

m, err := management.New(domain, management.WithStaticToken(token))
if err != nil {
    // handle err
}

With a management client we can then interact with the Authok Management API.

c := &management.Client{
    Name:        authok.String("Client Name"),
    Description: authok.String("Long description of client"),
}

err = m.Client.Create(c)
if err != nil {
    // handle err
}

Authentication

The authok package handles authentication by exchanging the client id and secret supplied when creating a new management client.

This is handled internally using the https://godoc.org/golang.org/x/oauth2 package.

Rate Limiting

The authok package also handles rate limiting by respecting the `X-Rate-Limit-*` headers sent by the server.

The amount of time the client waits for the rate limit to be reset is taken from the `X-Rate-Limit-Reset` header as the amount of seconds to wait.

Configuration

There are several other options that can be specified during the creation of a new client.

m, err := management.New(domain,
    management.WithClientCredentials(id, secret),
    management.WithContext(context.Background()),
    management.WithDebug(true))

Request Options

As with the global client configuration, fine-grained configuration can be done on a request basis.

c, err := m.Connection.List(
    management.Context(ctx),
    management.Page(2),
    management.PerPage(10),
    management.IncludeFields("id", "name", "options")
    management.Parameter("strategy", "authok"),
)

Index

Constants

This section is empty.

Variables

View Source
var Version = "latest"

Version of this library. This value is generated automatically during the release process; DO NOT EDIT.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolValue

func BoolValue(b *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func Float64

func Float64(f float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Value

func Float64Value(f *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Int

func Int(i int) *int

Int returns a pointer to the int value passed in.

func IntValue

func IntValue(i *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func String

func String(s string) *string

String returns a pointer to the string value passed in.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func Stringf

func Stringf(s string, v ...interface{}) *string

Stringf returns a pointer to the string value passed in formatted using fmt.Sprintf.

func Time

func Time(t time.Time) *time.Time

Time returns a pointer to the time value passed in.

func TimeValue

func TimeValue(t *time.Time) time.Time

TimeValue returns the value of the time pointer passed in or the zero value of time if the pointer is nil.

Types

This section is empty.

Directories

Path Synopsis
internal
tag

Jump to

Keyboard shortcuts

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