Reputation: 189
I want to get JWT Access token for Docusing, i tried use following code to get access token ,after that i pass access token to create envelope, i get an error
"Error calling CreateEnvelope: { "errorCode": "AUTHORIZATION_INVALID_TOKEN", "message": "The access token provided is expired, revoked or malformed." }"
Dim PrivateKey As String = "MIIEowIBAAKCAQEAjtTe7UUP/CBI9s...BLABLABLA...JfwZ2hHqFPXA9ecbhc0".Replace(vbLf, "").Replace(vbCr, "")
Dim ar1 As JObject = New JObject()
ar1.Add("typ", "JWT")
ar1.Add("alg", "RS256")
Dim header As String = Base64UrlEncoder.Encode(ar1.ToString)
Dim ar2 As JObject = New JObject()
ar2.Add("iss", "INTEGRATION_ID")
ar2.Add("sub", "GUID_VERSION_OF_USER_ID")
ar2.Add("iat", DateDiff(DateInterval.Second, New Date(1970, 1, 1), Now().ToUniversalTime))
ar2.Add("exp", DateDiff(DateInterval.Second, New Date(1970, 1, 1), DateAdd(DateInterval.Hour, 1,Now().ToUniversalTime)))
ar2.Add("aud", "account-d.docusign.com")
ar2.Add("scope", "signature")
Dim body As String = Base64UrlEncoder.Encode(ar2.ToString)
Dim stringToSign As String = header & "." & body
Dim bytesToSign() As Byte = Encoding.UTF8.GetBytes(stringToSign)
Dim keyBytes() As Byte = Convert.FromBase64String(PrivateKey)
Dim privKeyObj = Asn1Object.FromByteArray(keyBytes)
Dim privStruct = RsaPrivateKeyStructure.GetInstance(privKeyObj)
Dim sig As ISigner = SignerUtilities.GetSigner("SHA256withRSA")
sig.Init(True, New RsaKeyParameters(True, privStruct.Modulus, privStruct.PrivateExponent))
sig.BlockUpdate(bytesToSign, 0, bytesToSign.Length)
Dim signature() As Byte = sig.GenerateSignature()
Dim sign As String = Base64UrlEncoder.Encode(signature)
Return header & "." & body & "." & sign
I take above code from this link DocuSign JWT Access Token Request, in that user mention working code ,Pls advise me what i make mistakes, Note : I am get access token and immediately pass that token to create envelope. "iss" is my integration key and "sub" is my userid and Private keyi generate from RSA key pair form on of the my app which created in Apps and Integration Keys
i am use docusing 3.0.0 dll which support .net framework 4.6.1
Regards, Aravind
Upvotes: 0
Views: 791
Reputation: 14015
If you are using the DocuSign dll (version 3.0.0 is pretty old, I suggest you upgrade BTW) you don't need all this code. Instead you can do this: (note that I assume you have a configuration file with the information, you will want to update this code to include the ClientId/IK, UserId, AuthServer and RSA Key location).
Public Sub UpdateUserFromJWT()
Me._authToken = _apiClient.RequestJWTUserToken(Me._configuration("DocuSignJWT:ClientId"), Me._configuration("DocuSignJWT:ImpersonatedUserId"), Me._configuration("DocuSignJWT:AuthServer"), DSHelper.ReadFileContent(DSHelper.PrepareFullPrivateKeyFilePath(Me._configuration("DocuSignJWT:PrivateKeyFile"))), 1)
_account = GetAccountInfo(_authToken)
Me.User = New User With {
.Name = _account.AccountName,
.AccessToken = _authToken.access_token,
.ExpireIn = DateTime.Now.AddSeconds(_authToken.expires_in.Value),
.AccountId = _account.AccountId
}
Me.Session = New Session With {
.AccountId = _account.AccountId,
.AccountName = _account.AccountName,
.BasePath = _account.BaseUri
}
End Sub
Upvotes: 1