sso: github.com/e-mas-id/sso/pkg/client Index | Files

package client

import "github.com/e-mas-id/sso/pkg/client"

Index

Package Files

authorization.go client.go credential.go http.go login.go logout.go

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.

type BaseResponse Uses

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

BaseResponse is base response format from e-mas SSO.

type Client Uses

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 Uses

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

New to create a new e-mas SSO client.

func (*Client) AddQueryParam Uses

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

AddQueryParam to add query param in URL.

func (*Client) Authorize Uses

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

Authorize to authoorize customer SSO login for the first time.

func (*Client) ExecuteRequest Uses

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

ExecuteRequest to start http request.

func (*Client) GetHeader Uses

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

GetHeader to create header for authorization.

func (*Client) Login Uses

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

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

func (*Client) Logout Uses

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

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

func (*Client) NewRequest Uses

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 Uses

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

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

func (*Client) SetClientCredential Uses

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

SetClientCredential to set client id and secret.

func (*Client) SetClientName Uses

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

SetClientName to set client name.

func (*Client) SetDebug Uses

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

SetDebug to set client debug boolean value.

func (*Client) SetDomain Uses

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 Uses

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 Uses

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

SetToken to set client access token.

type CredentialRequest Uses

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

CredentialRequest is model for requesting client credentials.

type CredentialResponse Uses

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 Uses

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 Uses

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

LoginRequest is model to request login.

type LoginResponse Uses

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

LoginResponse is response model for login.

Package client imports 9 packages (graph) and is imported by 1 packages. Updated 2020-04-20. Refresh now. Tools for package owners.