Skip to content

Commit

Permalink
Golang Docusign support
Browse files Browse the repository at this point in the history
Signed-off-by: Harold Wanyama <hwanyama@contractor.linuxfoundation.org>
  • Loading branch information
nickmango committed Sep 18, 2023
1 parent e1c0394 commit 046d839
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
1 change: 1 addition & 0 deletions cla-backend-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ require (
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-github/v50 v50.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cla-backend-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/V
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/dep v0.5.4/go.mod h1:6RZ2Wai7dSWk7qL55sDYk+8UPFqcW7all2KDBraPPFA=
Expand Down
16 changes: 14 additions & 2 deletions cla-backend-go/v2/docusign_auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package docusignauth

import (
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"io"
"net/http"
Expand All @@ -16,7 +18,7 @@ import (
)

var (
baseURL = os.Getenv("DOCUSIGN_BASE_URL")
baseURL = os.Getenv("DOCUSIGN_AUTH_SERVER")
oauthTokenURL = baseURL + "/oauth/token"
jwtGrantAssertion = "urn:ietf:params:oauth:grant-type:jwt-bearer"
)
Expand All @@ -27,8 +29,18 @@ type TokenResponse struct {
}

func GetAccessToken(integrationKey, userGUID, privateKey string) (string, error) {
block, _ := pem.Decode([]byte(privateKey))
if block == nil {
return "", fmt.Errorf("failed to parse private key")
}

privateKeyParsed, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return "", err
}

// Generate the JWT token
tokenString, err := generateJWT(integrationKey, userGUID, privateKey)
tokenString, err := generateJWT(integrationKey, userGUID, privateKeyParsed.D.String())
if err != nil {
return "", err
}
Expand Down
47 changes: 47 additions & 0 deletions cla-backend-go/v2/main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"

"github.com/communitybridge/easycla/cla-backend-go/v2/docusign_auth"
)

func main() {
integrationKey := "557677f2-1e2f-4955-aaa6-1ef44630e01d"
userID := "3a1d118f-3083-4c25-8306-11b7400f7c03"
privateKey :=`
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAh0M2mIGaJjP8S/FxZR7nRsatCR/KpCPBFBbxalZffykqtTID
KNeDhJ5RvJKAVoJlLaLoUYSYloVaeSAwQdbn4F+Lsnll3mCGocwdl/W8998Lc/Ln
MaNQhpekBoXaq8vbj251jxnRcsdI9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UkIXG69l15L0su2qc
cbQj4tWkXY6c7exr4X/FAQKBgDmGTABFDU9puBoa/CeDSci4Wq1ehDrA/ai8KS8B
NFA1CtrIsLtuj7gPfFWf5levYEh1WgVIIILhAWiq+1oTV0NZdezsHOiOgcX0DAns
/zcgw/9LjtPMaamlFgBkYIWjxnre4ArVrniQcFV1IDuFm16189ApPMv7G1qzbt8+
XRH9AoGAceSrZLbceDkqgprTTV1BEOFY+Ti9edBIUW+CqN6KkB66OXHGWlab/PZc
OCHRPAjEijZcVXm8IPC2yi/s0agQAB8dKO2L1X0EtvxkWSg2s/YXFpp0QccQToTo
lRFb9injNzixUOq18Z62XcC/yqMB7QtgRw5x5OQk0HNWpL7h6KM=
-----END RSA PRIVATE KEY-----
`
token, err := docusignauth.GetAccessToken(integrationKey, userID, privateKey)
if err != nil {
fmt.Println(err)
}

fmt.Println(token)
}
18 changes: 18 additions & 0 deletions cla-backend-go/v2/sign/docusign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright The Linux Foundation and each contributor to LFX.
// SPDX-License-Identifier: MIT

package sign

import (
"context"
"log"
)

func (s *service) getAccessToken(ctx context.Context) (string, error) {
f := logrus.Fields{
"functionName": "sign.getAccessToken",
}

// Get the access token
jwtAssertion, jwterr := jwtToken()
}
17 changes: 17 additions & 0 deletions cla-backend-go/v2/sign/jwt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright The Linux Foundation and each contributor to LFX.
// SPDX-License-Identifier: MIT

package sign

import (
"github.com/golang-jwt/jwt"
"github.com/sirupsen/logrus"
)

const

func jwtToken() (string, error) {
claims := jwt.MapClaims{
"iss": ,
}
}

0 comments on commit 046d839

Please sign in to comment.