SDK for Go
安装
go get github.com/Authing/authing-go-sdk开始使用
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"regexp"
authing "github.com/Authing/authing-go-sdk"
prettyjson "github.com/hokaccha/go-prettyjson"
"github.com/kelvinji2009/graphql"
)
const (
userPoolId = "5adb75e03055230001023b26"
userPoolSecret = "e683d18f9d597317d43d7a6522615b9d"
)
func main() {
// ---User Endpoint
client := authing.NewClient(userPoolId, userPoolSecret, false)
// Enable debug info for graphql client, just comment it if you want to disable the debug info
client.Client.Log = func(s string) {
b := []byte(s)
pj, _ := prettyjson.Format(b)
fmt.Println(string(pj))
}
// >>>Graphql Mutation: register
input := authing.UserRegisterInput{
Email: graphql.String("kelvinji2009@gmail.com"),
Password: graphql.String("password"),
RegisterInClient: graphql.String(userPoolId),
}
m, err := client.Register(&input)
if err != nil {
log.Println(">>>>Register failed: " + err.Error())
} else {
printJSON(m)
}
// ---OAuth Endpoint
oauthClient := authing.NewOauthClient(userPoolId, userPoolSecret, false)
// Enable debug info for graphql client, just comment it if you want to disable the debug info
oauthClient.Client.Log = func(s string) {
b := []byte(s)
pj, _ := prettyjson.Format(b)
fmt.Println(string(pj))
}
// >>>>Graphql Query: Read OAuth List
readOauthListQueryParameter := authing.ReadOauthListQueryParameter{
ClientID: graphql.String(userPoolId),
DontGetURL: graphql.Boolean(false),
}
q, err := oauthClient.ReadOauthList(&readOauthListQueryParameter)
if err != nil {
log.Println(">>>>Read OAuth List failed: " + err.Error())
} else {
printJSON(q)
}
}
// printJSON prints v as JSON encoded with indent to stdout. It panics on any error.
func printJSON(v interface{}) {
w := json.NewEncoder(os.Stdout)
w.SetIndent("", "\t")
err := w.Encode(v)
if err != nil {
panic(err)
}
}API 使用实例
User Endpoint
注册一个新用户
用户登录
检查登录状态
查询用户信息
查询所有用户
删除用户
更新用户资料
发送邮箱验证邮件
发送重置密码邮件
验证重置密码的验证码
修改密码
OAuth Endpoint
读取 OAuth 列表
Last updated
Was this helpful?