SDK for Go

Authing Go SDK 目前支持 Golang 1.8+ 版本。

GitHub 地址:https://github.com/Authing/authing-go-sdk

安装

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 (
    clientID  = "5adb75e03055230001023b26"
    appSecret = "e683d18f9d597317d43d7a6522615b9d"
)

func main() {
    // ---User Endpoint
    client := authing.NewClient(clientID, appSecret, 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(clientID),
    }

    m, err := client.Register(&input)
    if err != nil {
        log.Println(">>>>Register failed: " + err.Error())
    } else {
        printJSON(m)
    }

    // ---OAuth Endpoint
    oauthClient := authing.NewOauthClient(clientID, appSecret, 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(clientID),
        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)
    }
}

如何获取 Client ID 和 Client Secret ?

API 使用实例

User Endpoint

请先创建一个用户 Endpoint Client。然后你可以对用户进行一系列操作,包括注册,登录,更新用户资料,删除用户,修改密码等等。

注册一个新用户

用户登录

检查登录状态

查询用户信息

查询所有用户

删除用户

更新用户资料

发送邮箱验证邮件

发送重置密码邮件

验证重置密码的验证码

修改密码

OAuth Endpoint

请先创建 OAuth Endpoint Client.

读取 OAuth 列表

Last updated

Was this helpful?