Skip to content

Latest commit

 

History

History
122 lines (93 loc) · 2.38 KB

README.md

File metadata and controls

122 lines (93 loc) · 2.38 KB

Account Golang SDK

The library is a Golang package for Single Account service API.

Get redirect authoriztion URL:

package main

import (
    "log"
    "github.com/corezoid/sdk-go/account/authurl"
    "github.com/corezoid/sdk-go/account/oauth"
)

func main() {
    api := authurl.New(oauth.Client{
        ClientId: "anId",
        ClientSecret: "aSecret",
        HttpHost: "https://account.corezoid.com",
        RedirectUri: "https://your.service/back/url",
    })
    
    url := api.AuthorizeUrl([]string{"single_account:account.read"})
    
    // redirect user to the url to processed with authorization.
}

Get access token by authorize code:

package main

import (
    "log"
    "github.com/corezoid/sdk-go/account/authcode"
    "github.com/corezoid/sdk-go/account/oauth"
)

func main() {
    authCode := oauth.AuthCode("anAuthorizationCode")

    api := authcode.New(oauth.Client{
        ClientId: "anId",
        ClientSecret: "aSecret",
        HttpHost: "https://account.corezoid.com",
        RedirectUri: "https://your.service/back/url",
    }, nil)
    
    r := api.Request(authCode).Decode()
    if r.Err != nil {
    	panic(r.Err)
    }
    defer r.Close()

    log.Printf("%+v", r)
}

Refresh access token:

package main

import (
    "log"
    "github.com/corezoid/sdk-go/account/authrefreshtoken"
    "github.com/corezoid/sdk-go/account/oauth"
)

func main() {
    token := oauth.RefreshToken("aRefreshToken")

    api := authrefreshtoken.New(oauth.Client{
        ClientId: "anId",
        ClientSecret: "aSecret",
        HttpHost: "https://account.corezoid.com",
        RedirectUri: "https://your.service/back/url",
    }, nil)
    
    r := api.Request(token).Decode()
    if r.Err != nil {
    	panic(r.Err)
    }
    defer r.Close()

    log.Printf("%+v", r)
}

Get user info:

package main

import (
    "log"
    "github.com/corezoid/sdk-go/account/userinfo"
    "github.com/corezoid/sdk-go/account/oauth"
)

func main() {
    token := oauth.AccessToken("anAccessToken")

    api := userinfo.New(oauth.Client{
        ClientId: "anId",
        ClientSecret: "aSecret",
        HttpHost: "https://account.corezoid.com",
        RedirectUri: "https://your.service/back/url",
    }, nil)
    
    r := api.Request(token).Decode()
    if r.Err != nil {
    	panic(r.Err)
    }
    defer r.Close()

    log.Printf("%+v", r)
}