client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Dev is environment type for development.
	Dev = "dev"
	// Prod is environment type for production.
	Prod = "prod"
	// DevDomainURL is domain URL for development environment.
	DevDomainURL = "https://oropay-dev.e-mas.com"
	// ProdDomainURL is domain URL for production environment.
	ProdDomainURL = "https://api.e-mas.com"
	// DefaultEnvironment is default environment type value.
	DefaultEnvironment = "dev"
	// DefaultDebug is default debug boolean value.
	DefaultDebug = true
)
View Source
const (
	// SuccessCode is success response header code.
	SuccessCode = 200
	// SuccessMessage is success response message.
	SuccessMessage = "success"
	// InternalErrorCode is internal response header code.
	InternalErrorCode = 500
)
View Source
const PathAuthorization = "/v1/sso/auth"

PathAuthorization is e-mas authorization endpoint.

View Source
const PathCredentialRequest = "/v1/sso/credential"

PathCredentialRequest is e-mas credential request endpoint.

View Source
const PathLogin = "/v1/sso/login"

PathLogin is e-mas login endpoint.

View Source
const PathLogout = "/v1/sso/logout"

PathLogout is e-mas loogout endpoint.

Variables

View Source
var DefaultClient = Client{
	Environment: DefaultEnvironment,
	Debug:       DefaultDebug,
}

DefaultClient is default client config.

Functions

This section is empty.

Types

type BaseResponse

type BaseResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

BaseResponse is base response format from e-mas SSO.

type Client

type Client struct {
	// ClientName is client name for using e-mas SSO.
	// Required when requesting client id and secret.
	ClientName string

	// ClientId and ClientSecret is client's credential data
	// that will be used for authorization. Need to be requested
	// for using client for the first time.
	ClientId     string
	ClientSecret string

	// Token is access token granted after login. Token will
	// be used in query params for most of e-mas sso endpoints.
	Token string

	// DomainURL is e-mas API domain URL depends on the environment.
	DomainURL string
	// Environment is environment type of the client.
	// Will affect the e-mas domain URL when initializing client.
	Environment string
	// Debug is boolean for debugging.
	Debug bool
}

Client is e-mas SSO client.

func New

func New(clientName string, clientCredentials ...string) *Client

New to create a new e-mas SSO client.

func (*Client) AddQueryParam

func (c *Client) AddQueryParam(request *http.Request, key, value string)

AddQueryParam to add query param in URL.

func (*Client) Authorize

func (c *Client) Authorize() (err error)

Authorize to authoorize customer SSO login for the first time.

func (*Client) ExecuteRequest

func (c *Client) ExecuteRequest(req *http.Request) (resp *http.Response, body []byte, err error)

ExecuteRequest to start http request.

func (*Client) GetHeader

func (c *Client) GetHeader() (header map[string]string)

GetHeader to create header for authorization.

func (*Client) Login

func (c *Client) Login(userPass ...string) (data CustomerData, err error)

Login to login e-mas SSO with username/password or token.

func (*Client) Logout

func (c *Client) Logout() (err error)

Logout to logout customer SSO login. Will invalidate current token.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, path string, body io.Reader, headers ...map[string]string) (*http.Request, error)

NewRequest to create new request for SSO.

func (*Client) RequestCredential

func (c *Client) RequestCredential() (client *Client, err error)

RequestCredential to request client credential (client_id & client_secret) to e-mas.

func (*Client) SetClientCredential

func (c *Client) SetClientCredential(clientId, clientSecret string) *Client

SetClientCredential to set client id and secret.

func (*Client) SetClientName

func (c *Client) SetClientName(clientName string) *Client

SetClientName to set client name.

func (*Client) SetDebug

func (c *Client) SetDebug(debug bool) *Client

SetDebug to set client debug boolean value.

func (*Client) SetDomain

func (c *Client) SetDomain(domainURL string) *Client

SetDomain to set e-mas API domain URL. Can be used if e-mas API is in localhost.

func (*Client) SetEnv

func (c *Client) SetEnv(env string) *Client

SetEnv to set client environment. This will set domain URL automatically depends on the environment. Don't call this function after SetDomain() or it will overwrite the domain URL.

func (*Client) SetToken

func (c *Client) SetToken(token string) *Client

SetToken to set client access token.

type CredentialRequest

type CredentialRequest struct {
	ClientName string `json:"client_name"`
}

CredentialRequest is model for requesting client credentials.

type CredentialResponse

type CredentialResponse struct {
	BaseResponse
	Data *struct {
		ClientId     string `json:"client_id"`
		ClientSecret string `json:"client_secret"`
	} `json:"data"`
}

CredentialResponse is response model for credential request.

type CustomerData

type CustomerData struct {
	Email  string `json:"email"`
	Phone  string `json:"phone"`
	Name   string `json:"name"`
	Gender string `json:"gender"`
}

CustomerData is customer data returned after login. Can be used by clients to provide general customer data for registering on their website.

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

LoginRequest is model to request login.

type LoginResponse

type LoginResponse struct {
	BaseResponse
	Data *struct {
		CustomerData
		Token  string `json:"token"`
		Avatar string `json:"avatar"`
	} `json:"data"`
}

LoginResponse is response model for login.

Jump to

Keyboard shortcuts

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