Documentation ¶
Index ¶
- Constants
- Variables
- type BaseResponse
- type Client
- func (c *Client) AddQueryParam(request *http.Request, key, value string)
- func (c *Client) Authorize() (err error)
- func (c *Client) ExecuteRequest(req *http.Request) (resp *http.Response, body []byte, err error)
- func (c *Client) GetHeader() (header map[string]string)
- func (c *Client) Login(userPass ...string) (data CustomerData, err error)
- func (c *Client) Logout() (err error)
- func (c *Client) NewRequest(method string, path string, body io.Reader, headers ...map[string]string) (*http.Request, error)
- func (c *Client) RequestCredential() (client *Client, err error)
- func (c *Client) SetClientCredential(clientId, clientSecret string) *Client
- func (c *Client) SetClientName(clientName string) *Client
- func (c *Client) SetDebug(debug bool) *Client
- func (c *Client) SetDomain(domainURL string) *Client
- func (c *Client) SetEnv(env string) *Client
- func (c *Client) SetToken(token string) *Client
- type CredentialRequest
- type CredentialResponse
- type CustomerData
- type LoginRequest
- type LoginResponse
Constants ¶
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 )
const ( // SuccessCode is success response header code. SuccessCode = 200 // SuccessMessage is success response message. SuccessMessage = "success" // InternalErrorCode is internal response header code. InternalErrorCode = 500 )
const PathAuthorization = "/v1/sso/auth"
PathAuthorization is e-mas authorization endpoint.
const PathCredentialRequest = "/v1/sso/credential"
PathCredentialRequest is e-mas credential request endpoint.
const PathLogin = "/v1/sso/login"
PathLogin is e-mas login endpoint.
const PathLogout = "/v1/sso/logout"
PathLogout is e-mas loogout endpoint.
Variables ¶
var DefaultClient = Client{ Environment: DefaultEnvironment, Debug: DefaultDebug, }
DefaultClient is default client config.
Functions ¶
This section is empty.
Types ¶
type BaseResponse ¶
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 (*Client) AddQueryParam ¶
AddQueryParam to add query param in URL.
func (*Client) ExecuteRequest ¶
ExecuteRequest to start http request.
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) 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 ¶
RequestCredential to request client credential (client_id & client_secret) to e-mas.
func (*Client) SetClientCredential ¶
SetClientCredential to set client id and secret.
func (*Client) SetClientName ¶
SetClientName to set client name.
func (*Client) SetDomain ¶
SetDomain to set e-mas API domain URL. Can be used if e-mas API is in localhost.
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.