2 years ago

#41209

test-img

Dario

Jira Forge App - SSL OAuth 2.0 Authentication

I’m creating a Forge App that integrates Jira Service Management with an external ticketing system.

The external system uses an SLL OAuth 2 authentication, so in order to get the token and use it for the rest call, I have to send the Certificate (.crt) and the private key (.key) with the client_id and client_secret to the server.

I need a way to send these two files to the client’s server, but I wasn’t able to find a way to do it.

Here is my code:

import api, {route} from '@forge/api';   
let cert = "-----BEGIN CERTIFICATE-----\n" +
    "MIIDRDCCAiwCAQQwDQYJKoZIhvcNAQELBQAweTELMAkGA1UEBhMCSVQxEDAOBgNV\n" +
    "BAgMB0JvbG9nbmExEDAOBgNVBAcMB0JvbG9nbmExIDAeBgNVBAoMF1VuaXBvbFNh\n" +
    "..." +
    "og/IUwTIPFuegxxxxxxxxxxxxxxxxpa\n" +
    "-----END CERTIFICATE-----";

let key = "-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
    "MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIXFFnE+tfDz0CAggA\n" +
    "..." +
    "xdqpWX05RXxxxxxUHcccc==\n" +
    "-----END ENCRYPTED PRIVATE KEY-----";

let agent = new https.Agent();
agent.options.cert = cert;
agent.options.key = key;
agent.options.passphrase = "password!!";


let options = {
    body: "body",
    method: "POST",
    agent: agent
}

await api.fetch("https://external.endopoint.com/token", options).then(res => {
    console.error(res);
}).catch(error => {
    console.error(error);
})

I'm getting this error:

TypeError: https__WEBPACK_IMPORTED_MODULE_1___default.a.Agent is not a constructor

I tried to use fs.readFileSync but apparently I can't do it in Forge for Jira, this is why I'm trying to send the strings.

Can someone help me, please?

Thanks,

D.

rest

ssl-certificate

cloud

jira

forge

0 Answers

Your Answer

Accepted video resources