gauth

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

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 6 Imported by: 0

README

gauth-go


Go Reference codecov Go Report Card

Package gauth is go version of gauth sdk.

Description


광주소프트웨어 마이스터고등학교의 통합 계정 관리 서비스인 GAuthGolang으로 더 손쉽게 사용할 수 있도록 만들어진 라이브러리 입니다

Installation

go get -u https://github.com/onee-only/gauth-go

How To Use

Client Initialization
package main

import(
	"github.com/onee-only/gauth-go"
)

func main() {
	client := gauth.NewDefaultClient(gauth.ClientOpts{
		ClientID:     "clientID",
		ClientSecret: "clientSecret",
		RedirectURI:  "localhost:8080",
	})
}
code 발급
package main

import (
	"log"
	
	"github.com/onee-only/gauth-go"
)

func issueCode(client *gauth.Client) {
	code, err := client.IssueCode("email", "password")
	if err != nil {
		// You shouldn't use panic in your code.
		panic(err)
	}
	log.Println(code)
}
Token 발급
package main

import (
	"log"

	"github.com/onee-only/gauth-go"
)

func issueToken(client *gauth.Client) {
	accessToken, refreshToken, err := client.IssueToken("code")
	if err != nil {
		// You shouldn't use panic in your code.
		panic(err)
	}
	log.Println(accessToken)
	log.Println(refreshToken)
}
Token 재발급
package main

import (
	"log"
	
	"github.com/onee-only/gauth-go"
)

func reIssueToken(client *gauth.Client) {
	access, refresh, err := client.ReIssueToken("refreshToken")
	if err != nil {
		// You shouldn't use panic in your code.
		panic(err)
	}
	log.Println(access)
	log.Println(refresh)
}
유저 정보 가져오기
package main

import (
	"log"
	
	"github.com/onee-only/gauth-go"
)

func getUserInfo(client *gauth.Client) {
	info, err := client.GetUserInfo("accessToken")
	if err != nil {
		// You shouldn't use panic in your code.
		panic(err)
	}
	log.Println(info)
}

Documentation

Index

Constants

View Source
const (
	GenderMale   gender = "MALE"
	GenderFemale gender = "FEMALE"
)
View Source
const (
	RoleStudent  role = "ROLE_STUDENT"
	RoleTeacher  role = "ROLE_TEACHER"
	RoleGraduate role = "ROLE_GRADUATE"
)
View Source
const (
	AuthURL     = "https://server.gauth.co.kr"
	ResourceURL = "https://open.gauth.co.kr"
)
View Source
const (
	CodeExpiresIn    = 15 * time.Minute
	AccessExpiresIn  = 15 * time.Minute
	RefreshExpiresIn = 7 * 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(httpClient *http.Client, opts ClientOpts) *Client

NewDefaultClient creates GAuth client with given client

func NewDefaultClient

func NewDefaultClient(opts ClientOpts) *Client

NewDefaultClient creates GAuth client with http.DefaultClient

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(accessToken string) (info UserInfo, err error)

GetUserInfo retrieves userInfo with given access token

func (*Client) IssueCode

func (c *Client) IssueCode(email, password string) (code string, err error)

IssueCode retrieves code with given email and password

func (*Client) IssueToken

func (c *Client) IssueToken(code string) (access, refresh string, err error)

IssueToken retrieves access & refresh token with given code

func (*Client) ReIssueToken

func (c *Client) ReIssueToken(refreshToken string) (access, refresh string, err error)

ReIssueToken retrieves access & refresh token with given refresh token

type ClientOpts

type ClientOpts struct {
	ClientID     string
	ClientSecret string
	RedirectURI  string
}

type GauthErr

type GauthErr struct {
	Code    int
	Message string
}

GauthErr is returned when http request's status >= 400.

func (*GauthErr) Error

func (e *GauthErr) Error() string

type UserInfo

type UserInfo struct {
	Email      string
	Name       *string
	Grade      *int
	ClassNum   *int
	Num        *int
	Gender     gender
	ProfileURL *string
	Role       role
}

Jump to

Keyboard shortcuts

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