Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
// You can edit this code!
// Click here and start typing.
package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
	"strconv"
	"strings"
	"time"
)

func main() {

	const appSecret = "K7kC8cIxDT7R0AOrvDDjQ20QnEixpWiqxduSPIuiE0o="
	const version = "2"
	const url = "https://oneidentityapi-qa.aexp.com/security/digital/v1/application/token"
	const appId = "0d5fb68f-11c4-3e1c-9844-a3af130d49c9"
	const scope = "/acp/v1/partners/appRegistration/**::post|delete"
	timeStamp := getCurrentTimestampForCBISSignature()
	fmt.Println("timestamp is", timeStamp)
	if key, err := base64.StdEncoding.DecodeString(strings.TrimSpace(appSecret)); err == nil {
		inputArr := []string{strings.TrimSpace(appId), strings.TrimSpace(version), timeStamp}
		input := strings.Join(inputArr, "-")
		h := hmac.New(sha256.New, key)
		h.Write([]byte(input))
		strSrc := base64.RawURLEncoding.EncodeToString(h.Sum(nil))
		//req := scope
		fmt.Println(strSrc)
	}

}
func getCurrentTimestampForCBISSignature() (timeStamp string) {
	now := time.Now().UnixNano()
	milliSec := now / 1000000
	timeStamp = strconv.FormatInt(milliSec, 10)
	return
}