Skip to content

Commit 9896045

Browse files
#main: comments updated
1 parent 6850857 commit 9896045

File tree

5 files changed

+71
-116
lines changed

5 files changed

+71
-116
lines changed

helper.go

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,10 @@ func GenerateBaseString(httpMethod string, apiURL string, appId string, params P
9898
return baseString
9999
}
100100

101-
/**
102-
* Get Private Key
103-
*
104-
* This methods will decrypt P12 Certificate and retrieve the Private key with the passphrase
105-
106-
* Returns private key from p12
107-
*/
101+
/*
102+
This methods will decrypt P12 Certificate and retrieve the Private key with the passphrase.
103+
Returns private key from p12.
104+
*/
108105
func DecryptPrivateKey(secureCertLocation string, passphrase string) (*rsa.PrivateKey, error) {
109106
fileData, err := ioutil.ReadFile(secureCertLocation)
110107
if err != nil {
@@ -123,13 +120,10 @@ func DecryptPrivateKey(secureCertLocation string, passphrase string) (*rsa.Priva
123120
return privateKey, nil
124121
}
125122

126-
/**
127-
* Generate Random Hex
128-
*
129-
* This method helps to generate unique Transaction ID(txnNo)
130-
*
131-
* Returns random hex(txnNo)
132-
*/
123+
/*
124+
This method helps to generate unique Transaction ID(txnNo).
125+
Returns random hex(txnNo).
126+
*/
133127
func GenerateRandomHex(count int) (string, error) {
134128
bytes := make([]byte, count)
135129
_, err := rand.Read(bytes)
@@ -140,14 +134,11 @@ func GenerateRandomHex(count int) (string, error) {
140134
return randomHex, nil
141135
}
142136

143-
/**
144-
* Generate Authorization Header
145-
*
146-
* This method helps to generate the authorization header and sign it
147-
* using the private key. This is required to be used for both Token and Person API
148-
*
149-
* Returns Signed Header
150-
*/
137+
/*
138+
This method helps to generate the authorization header and sign it using the private key.
139+
This is required to be used for both Token and Person API.
140+
Returns Signed Header
141+
*/
151142
func GenerateAuthorizationHeader(apiURL string, params ParamsSort, httpMethod string, contentType string, environment string, appId string, privateKey *rsa.PrivateKey, clientSecret string) (string, error) {
152143
nonceValue, err := GenerateRandomHex(20)
153144
if err != nil {
@@ -176,13 +167,10 @@ func GenerateAuthorizationHeader(apiURL string, params ParamsSort, httpMethod st
176167
}
177168
}
178169

179-
/**
180-
* Decode
181-
*
182-
* This method helps to decode the payload data into normal form.
183-
*
184-
* Returns normalized(decoded) []byte.
185-
*/
170+
/*
171+
This method helps to decode the payload data into normal form.
172+
Returns normalized(decoded) []byte.
173+
*/
186174
func Decode(payload string) ([]byte, error) {
187175
s := strings.Split(payload, ".")
188176
if len(s) < 2 {
@@ -196,16 +184,13 @@ func Decode(payload string) ([]byte, error) {
196184
return decodedData, err
197185
}
198186

199-
/**
200-
* Verify JWS
201-
*
202-
* This method takes in a JSON Web Signature and will check against
203-
* the public key for its validity and to retrieve the decoded data.
204-
* This verification is required for the decoding of the access token and
205-
* response from Person API
206-
*
207-
* Returns decoded data
208-
*/
187+
/*
188+
This method takes in a JSON Web Signature and will check against
189+
the public key for its validity and to retrieve the decoded data.
190+
This verification is required for the decoding of the access token and
191+
response from Person API.
192+
Returns decoded data.
193+
*/
209194
func VerifyJWS(publicCert string, accessToken string) ([]byte, error) {
210195
keyData, err := ioutil.ReadFile(publicCert)
211196
if err != nil {
@@ -234,14 +219,11 @@ func VerifyJWS(publicCert string, accessToken string) ([]byte, error) {
234219
return claimSet, nil
235220
}
236221

237-
/**
238-
* Decypt JWE
239-
*
240-
* This method takes in a JSON Web Encrypted string and will decrypt it using the
241-
* private key. This is required to decrypt the data from Person API
242-
*
243-
* Returns decrypted data
244-
*/
222+
/*
223+
This method takes in a JSON Web Encrypted string and will decrypt it using the private key.
224+
This is required to decrypt the data from Person API.
225+
Returns decrypted data.
226+
*/
245227
func DecryptJWE(pemPrivaKey *rsa.PrivateKey, compactJWE string) (string, error) {
246228
payload, err := jose.ParseEncrypted(compactJWE)
247229
if err != nil {
@@ -263,13 +245,10 @@ func Unmarshal(data []byte, v interface{}) error {
263245
return nil
264246
}
265247

266-
/**
267-
* AuthHeader
268-
*
269-
* This method removes the duplication use of environment based condition for generating auth header.
270-
*
271-
* Returns fully generated auth Header as string.
272-
*/
248+
/*
249+
This method removes the duplication use of environment based condition for generating auth header.
250+
Returns fully generated auth Header as string.
251+
*/
273252
func AuthHeader(apiURL string, params ParamsSort, httpMethod string, contentType string, environment string, appId string, privateKey *rsa.PrivateKey, clientSecret string) (string, error) {
274253
var authHeader string
275254
var err error

person.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ import (
88
"net/http"
99
)
1010

11-
/**
12-
* Get Person Data from MyInfo Person API
13-
*
14-
* This method calls the Person API and returns a JSON response with the
15-
* personal data that was requested. Your application needs to provide a
16-
* valid "access token" in exchange for the JSON data. Once your application
17-
* receives this JSON data, you can use this data.
18-
*
19-
* Returns the Person Data (Payload decrypted + Signature validated)
20-
*/
11+
/*
12+
This method calls the Person API and returns a JSON response with the personal data that was requested.
13+
Your application needs to provide a valid "access token" in exchange for the JSON data.
14+
Once your application receives this JSON data, you can use this data.
15+
Returns the Person Data (Payload decrypted + Signature validated).
16+
*/
2117

2218
func (appConfig AppConfig) GetPersonData(accessToken, txnNo string) ([]byte, error) {
2319
if !isInitialized {
@@ -38,15 +34,12 @@ func (appConfig AppConfig) GetPersonData(accessToken, txnNo string) ([]byte, err
3834

3935
}
4036

41-
/**
42-
* Get Person Data With Key
43-
*
44-
* This method will take in the accessToken from Token API and decode it
45-
* to get the sub(eg either uinfin or uuid). It will call the Person API using the token and sub.
46-
* It will verify the Person API data's signature and decrypt the result.
47-
*
48-
* Returns decrypted result from calling Person API
49-
*/
37+
/*
38+
This method will take in the accessToken from Token API and decode it to get the sub(eg either uinfin or uuid).
39+
It will call the Person API using the token and sub.
40+
It will verify the Person API data's signature and decrypt the result.
41+
Returns decrypted result from calling Person API.
42+
*/
5043
func (appConfig AppConfig) GetPersonDataWithKey(accessToken, txnNo string, privateKey *rsa.PrivateKey) ([]byte, error) {
5144
if !isInitialized {
5245
return nil, errors.New(ERROR_UNKNOWN_NOT_INIT)
@@ -93,14 +86,10 @@ func (appConfig AppConfig) GetPersonDataWithKey(accessToken, txnNo string, priva
9386

9487
}
9588

96-
/**
97-
* Call Person API
98-
*
99-
* This method will generate the Authorization Header and
100-
* and call the Person API to get the encrypted Person Data
101-
*
102-
* Returns result from calling Person API
103-
*/
89+
/*
90+
This method will generate the Authorization Header and call the Person API to get the encrypted Person Data.
91+
Returns result from calling Person API.
92+
*/
10493
func (appConfig AppConfig) CallPersonAPI(sub, accessToken, txnNo string, privateKey *rsa.PrivateKey) ([]byte, error) {
10594
if !isInitialized {
10695
return nil, errors.New(ERROR_UNKNOWN_NOT_INIT)

request.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import (
88
"net/http"
99
)
1010

11-
/**
12-
* Send Request
13-
*
14-
* This function is a wrapper to make https call
15-
*
16-
* Returns the response of the hit api
17-
*/
11+
/*
12+
This function is a wrapper to make https call.
13+
Returns the response of the hit api.
14+
*/
1815
func SendRequest(request *http.Request) ([]byte, error) {
1916
client := &http.Client{
2017
Transport: &http.Transport{

singpass.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,13 @@ func (appConfig AppConfig) CheckConfig() error {
8383
return nil
8484
}
8585

86-
/**
87-
* Get MyInfo Person Data (MyInfo Token + Person API)
88-
*
89-
* This method takes in all the required variables, invoke the following APIs.
90-
* - Get Access Token (Token API) - to get Access Token by using the Auth Code and State
91-
* - Get Person Data (Person API) - to get Person Data by using the Access Token
92-
*
93-
* Returns the Person Data as []byte (Payload decrypted + Signature validated)
94-
*
95-
*/
86+
/*
87+
Get MyInfo Person Data (MyInfo Token + Person API).
88+
This method takes in all the required variables, invoke the following APIs.
89+
Get Access Token (Token API) - to get Access Token by using the Auth Code and State.
90+
Get Person Data (Person API) - to get Person Data by using the Access Token.
91+
Returns the Person Data as []byte (Payload decrypted + Signature validated).
92+
*/
9693
func (appConfig AppConfig) GetMyInfoPersonData(authCode, state string) ([]byte, error) {
9794
if !isInitialized {
9895
return nil, errors.New(ERROR_UNKNOWN_NOT_INIT)

token.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import (
88
"strings"
99
)
1010

11-
/**
12-
* Get Access Token from MyInfo Token API
13-
*
14-
* This method calls the Token API and obtain an "access token" from response,
15-
* which can be used to call the Person API for the actual data.
16-
* Your application needs to provide a valid "authorisation code"
17-
* from the authorise API(callback) in exchange for the valid "access token".
18-
*
19-
* Returns the Access Token API response as []byte which includes all data sent by Access Token API
20-
*/
11+
/*
12+
This method calls the Token API and obtain an "access token" from response,
13+
which can be used to call the Person API for the actual data.
14+
Your application needs to provide a valid "authorisation code"
15+
from the authorise API(callback) in exchange for the valid "access token".
16+
Returns the Access Token API response as []byte which includes all data sent by Access Token API.
17+
*/
2118

2219
func (appConfig AppConfig) GetAccessToken(authCode string, state string) ([]byte, error) {
2320
if !isInitialized {
@@ -38,14 +35,10 @@ func (appConfig AppConfig) GetAccessToken(authCode string, state string) ([]byte
3835
return tokenData, nil
3936
}
4037

41-
/**
42-
* Call (Access) Token API
43-
*
44-
* This method will generate the Authorization Header
45-
* and call the Token API to retrieve access token.
46-
*
47-
* Returns the full json response as []byte.
48-
*/
38+
/*
39+
This method will generate the Authorization Header and call the Token API to retrieve access token.
40+
Returns the full json response as []byte.
41+
*/
4942
func (appConfig AppConfig) CallTokenAPI(authCode string, privateKey *rsa.PrivateKey, state string) ([]byte, error) {
5043
if !isInitialized {
5144
return nil, errors.New(ERROR_UNKNOWN_NOT_INIT)

0 commit comments

Comments
 (0)