myinfoconnectorgolang

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 23 Imported by: 0

README

myinfo-connector-golang

Documentation

Index

Constants

View Source
const (
	ERROR                                                       string = "error"
	OK                                                          string = "OK"
	INVALID_TOKEN                                               string = "invalid token"
	UINFIN_NOT_FOUND                                            string = "uinfin not found"
	PERSON_DATA_NOT_FOUND                                       string = "person data not found"
	INVALID_DATA_OR_SIGNATURE                                   string = "invalid data or signature for person data"
	ERROR_CONFIGURATION_PUBLIC_CERT_NOT_FOUND                   string = "public cert not found"
	ERROR_CONFIGURATION_CLIENT_ID_NOT_FOUND                     string = "client id not found"
	ERROR_CONFIGURATION_CLIENT_SECRET_NOT_FOUND                 string = "client secret not found"
	ERROR_CONFIGURATION_REDIRECT_URL_NOT_FOUND                  string = "redirect URL not found"
	ERROR_CONFIGURATION_CLIENT_SECURE_CERT_NOT_FOUND            string = "client secure cert not found"
	ERROR_CONFIGURATION_CLIENT_SECURE_CERT_PASSPHRASE_NOT_FOUND string = "client passphrase not found"
	ERROR_CONFIGURATION_ENVIRONMENT_NOT_FOUND                   string = "environment not found"
	ERROR_CONFIGURATION_TOKEN_URL_NOT_FOUND                     string = "token URL not found"
	ERROR_CONFIGURATION_PERSON_URL_NOT_FOUND                    string = "person URL not found"
	ERROR_CONFIGURATION_ATTRIBUTES_NOT_FOUND                    string = "attributes not found"
	ERROR_CONFIGURATION_PROXY_TOKEN_URL_NOT_FOUND               string = "proxy token URL not found"
	ERROR_CONFIGURATION_PROXY_PERSON_URL_NOT_FOUND              string = "proxy person URL not found"
	ERROR_UNKNOWN_AUTH_LEVEL                                    string = "unknown auth level"
	ERROR_UNKNOWN_NOT_INIT                                      string = "configurations not initialized"
	HTTP_METHOD_GET                                             string = http.MethodGet
	HTTP_METHOD_POST                                            string = http.MethodPost
	CONTENT_TYPE                                                string = "application/x-www-form-urlencoded"
	FAILED_TO_PARSE_RSA_PRIVATE_KEY                             string = "unable to parse rsa private key"
	SINPASS_TEST_ENVIRONMENT                                    string = "TEST"
	SINPASS_SANDBOX_ENVIRONMENT                                 string = "SANDBOX"
	SINPASS_PRODUCTION_ENVIRONMENT                              string = "PRODUCTION"
	APP_ID                                                      string = "app_id"
	NONCE                                                       string = "nonce"
	SIGNATURE_METHOD                                            string = "signature_method"
	RS256                                                       string = "RS256"
	TIMESTAMP                                                   string = "timestamp"
	PARAM_REDIRECT_URL                                          string = "redirect_uri"
	PARAM_CLIENT_ID                                             string = "client_id"
	PARAM_CLIENT_SECRET                                         string = "client_secret"
	PARAM_CODE                                                  string = "code"
	PARAM_GRANT_TYPE                                            string = "grant_type"
	AUTHORIZATION_CODE                                          string = "authorization_code"
	PARAM_STATE                                                 string = "state"
	AUTHORIZATION                                               string = "Authorization"
	CACHE_CONTROL                                               string = "Cache-Control"
	NO_CACHE                                                    string = "no-cache"
	CONTENT                                                     string = "Content-Type"
	UNEXPECTED_STATUS_CODE                                      string = "unexpected status code found:"
	PARAM_ATTRIBUTES                                            string = "attributes"
	PARAM_TXNNO                                                 string = "txnNo"
	BEARER                                                      string = "Bearer"
)

Variables

This section is empty.

Functions

func AuthHeader

func AuthHeader(apiURL string, params ParamsSort, httpMethod string, contentType string, environment string, appId string, privateKey *rsa.PrivateKey, clientSecret string) (string, error)

*

  • AuthHeader *
  • This method removes the duplication use of environment based condition for generating auth header. *
  • Returns fully generated auth Header as string.

func Decode

func Decode(payload string) ([]byte, error)

*

  • Decode *
  • This method helps to decode the payload data into normal form. *
  • Returns normalized(decoded) []byte.

func DecryptJWE

func DecryptJWE(pemPrivaKey *rsa.PrivateKey, compactJWE string) (string, error)

*

  • Decypt JWE *
  • This method takes in a JSON Web Encrypted string and will decrypt it using the
  • private key. This is required to decrypt the data from Person API *
  • Returns decrypted data

func DecryptPrivateKey

func DecryptPrivateKey(secureCertLocation string, passphrase string) (*rsa.PrivateKey, error)

*

  • Get Private Key *

  • This methods will decrypt P12 Certificate and retrieve the Private key with the passphrase

  • Returns private key from p12

func GenerateAuthorizationHeader

func GenerateAuthorizationHeader(apiURL string, params ParamsSort, httpMethod string, contentType string, environment string, appId string, privateKey *rsa.PrivateKey, clientSecret string) (string, error)

*

  • Generate Authorization Header *
  • This method helps to generate the authorization header and sign it
  • using the private key. This is required to be used for both Token and Person API *
  • Returns Signed Header

func GenerateBaseString

func GenerateBaseString(httpMethod string, apiURL string, appId string, params ParamsSort, contentType string, nonceValue string, timestamp string) string

func GenerateRandomHex

func GenerateRandomHex(count int) (string, error)

*

  • Generate Random Hex *
  • This method helps to generate unique Transaction ID(txnNo) *
  • Returns random hex(txnNo)

func GenerateSignature

func GenerateSignature(privateKey *rsa.PrivateKey, baseString string) (string, error)

func MyInfoConnector

func MyInfoConnector(appConfig AppConfig) error

This function validate and initialize all the config variables

func SendRequest

func SendRequest(request *http.Request) ([]byte, error)

*

  • Send Request *
  • This function is a wrapper to make https call *
  • Returns the response of the hit api

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

func VerifyJWS

func VerifyJWS(publicCert string, accessToken string) ([]byte, error)

*

  • Verify JWS *
  • This method takes in a JSON Web Signature and will check against
  • the public key for its validity and to retrieve the decoded data.
  • This verification is required for the decoding of the access token and
  • response from Person API *
  • Returns decoded data

Types

type AppConfig

type AppConfig struct {
	MYINFO_SIGNATURE_CERT_PUBIC_CERT string
	CLIENT_ID                        string
	CLIENT_SECRET                    string
	CLIENT_SECURE_CERT               string
	CLIENT_SECURE_CERT_PASSPHRASE    string
	REDIRECT_URL                     string
	PURPOSE                          string
	ATTRIBUTES                       string
	ENVIRONMENT                      string
	TOKEN_URL                        string
	PERSON_URL                       string

	// Proxy parameters (OPTIONAL)
	USE_PROXY        string // Indicate whether proxy url is used. i.e Y or N
	PROXY_TOKEN_URL  string // Configure your proxy url here, if any
	PROXY_PERSON_URL string // Configure your proxy url here, if anys
}

App Config structure

func (AppConfig) CallPersonAPI

func (appConfig AppConfig) CallPersonAPI(sub, accessToken, txnNo string, privateKey *rsa.PrivateKey) ([]byte, error)

*

  • Call Person API *
  • This method will generate the Authorization Header and
  • and call the Person API to get the encrypted Person Data *
  • Returns result from calling Person API

func (AppConfig) CallTokenAPI

func (appConfig AppConfig) CallTokenAPI(authCode string, privateKey *rsa.PrivateKey, state string) ([]byte, error)

*

  • Call (Access) Token API *
  • This method will generate the Authorization Header
  • and call the Token API to retrieve access token. *
  • Returns the full json response as []byte.

func (AppConfig) CheckConfig

func (appConfig AppConfig) CheckConfig() error

func (AppConfig) GetAccessToken

func (appConfig AppConfig) GetAccessToken(authCode string, state string) ([]byte, error)

func (AppConfig) GetMyInfoPersonData

func (appConfig AppConfig) GetMyInfoPersonData(authCode, state string) ([]byte, error)

* * Get MyInfo Person Data (MyInfo Token + Person API) * * This method takes in all the required variables, invoke the following APIs. * - Get Access Token (Token API) - to get Access Token by using the Auth Code and State * - Get Person Data (Person API) - to get Person Data by using the Access Token * * Returns the Person Data as []byte (Payload decrypted + Signature validated) *

func (AppConfig) GetPersonData

func (appConfig AppConfig) GetPersonData(accessToken, txnNo string) ([]byte, error)

func (AppConfig) GetPersonDataWithKey

func (appConfig AppConfig) GetPersonDataWithKey(accessToken, txnNo string, privateKey *rsa.PrivateKey) ([]byte, error)

*

  • Get Person Data With Key *
  • This method will take in the accessToken from Token API and decode it
  • to get the sub(eg either uinfin or uuid). It will call the Person API using the token and sub.
  • It will verify the Person API data's signature and decrypt the result. *
  • Returns decrypted result from calling Person API

type Params

type Params struct {
	Name  string
	Value string
}

type ParamsSort

type ParamsSort []Params

func (ParamsSort) Len

func (slice ParamsSort) Len() int

func (ParamsSort) Less

func (slice ParamsSort) Less(i, j int) bool

func (ParamsSort) Swap

func (slice ParamsSort) Swap(i, j int)

Jump to

Keyboard shortcuts

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