Last active
July 24, 2023 15:43
-
-
Save sandrinodimattia/b34de0a8b52f6bbc7b845c50a3562ae3 to your computer and use it in GitHub Desktop.
Create SAML connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { AuthenticationClient, ManagementClient } = require("auth0"); | |
const publicKey = `-----BEGIN CERTIFICATE----- | |
MIIC/zCCAeegAwIBAgIJHqZ8xG7fkm2bMA0GCSqGSIb3DQEBCwUAMB0xGzAZBgNV | |
BAMTEnNhbWwtaWRwLmF1dGgwLmNvbTAeFw0xNzA4MDMxNDE0MTBaFw0zMTA0MTIx | |
NDE0MTBaMB0xGzAZBgNVBAMTEnNhbWwtaWRwLmF1dGgwLmNvbTCCASIwDQYJKoZI | |
hvcNAQEBBQADggEPADCCAQoCggEBAOzFui1uCqya7hcEW6TwLQn4kfw0gXDoZ018 | |
VYVA9U45GQGuJPOVjXlNYDxwysjZXP9mOn322wL7AQGejavdrwsGFgiLZ23/X9DP | |
TsyGTcNuQtFCbW16xQcBB7PuLy3iluFXi50c+dvU/iSdBG9xEhndQ9mVtwbFMMFf | |
q8WNY4arU3PmnxFAhZIXgTmJih9a8hknGL82pgpcmK4iQof6Uw35x2Gg9X4zbbyt | |
jGc0xIvybuYKxE17/hqabzoGlZYDl4GSeGiH9RdllipPOcvapIWAaVxcYLJG905b | |
SANU1ol9pWFlhL+zyjvFNFqf1N4dnNt3c9AHVkOVQvDNYwnDuRsCAwEAAaNCMEAw | |
DwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUIBC4Ejl9APjdqn3v/KeBzPtaBYgw | |
DgYDVR0PAQH/BAQDAgKEMA0GCSqGSIb3DQEBCwUAA4IBAQA0EFLEhOn1onGF5q/t | |
kHwL2+Qgnq+yAP8wxdKUnztEUyL5rl0G+ny+TdaNVIchSUwiOL8LUG2Vbt39eWst | |
9UNRgkjfk4vmf6A5DXECwNGPVscJAVQtj3giA0ux5uee9AsfV3tfGw98cCt5PPWG | |
2s5w/2jVdwd/qfF70JBPqD1fnKLy/iko2L0Y90gWC5gfowHc9la1X6VBEgLwJSKf | |
mxczd6LhOg+RBN6juSjsbgheAVkvJbQDvu+lAtBIAVg6tEtSY85wzphWFQnnN9xg | |
lS1ZUdscqinDnGbhgdicldfAhjtuDG5vh1M8ToKCnqnnwUXG0YtDZykpZ0dOYxBM | |
yY3k | |
-----END CERTIFICATE-----`; | |
const domain = "sandrino-dev.auth0.com"; | |
const authenticationApi = new AuthenticationClient({ | |
domain, | |
clientId: "XeJodlO9npk7YOgRWkL83fvXYfsooj8u", | |
clientSecret: "...", | |
}); | |
// This logic will run on your backend API | |
const run = async () => { | |
// In production you would cache this access token for as long as it is valid. | |
// This token must not be exposed to the client. | |
const { access_token } = await authenticationApi | |
.clientCredentialsGrant({ audience: `https://${domain}/api/v2/` }); | |
const managementApi = new ManagementClient({ | |
domain, | |
token: access_token | |
}); | |
const response = await managementApi.createConnection({ | |
options: { | |
signingCert: Buffer.from(publicKey).toString('base64'), | |
signInEndpoint: | |
"https://employee-login.acmeairlines.net/samlp/IVZ0ZRSW4oEobJNOU8BmSPkHvo5fNTtR", | |
protocolBinding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST", | |
signOutEndpoint: "", | |
signSAMLRequest: true, | |
signatureAlgorithm: "rsa-sha256", | |
domain_aliases: [ | |
"acme-airlines.com" | |
] | |
}, | |
strategy: "samlp", | |
name: "acme-saml", | |
show_as_button: false, | |
enabled_clients: [ | |
// Clients go here | |
], | |
display_name: "ACME Airlines", | |
metadata: { | |
customer_name: 'acme' | |
} | |
}); | |
console.log(response); | |
}; | |
run().catch((err) => console.error(err.message)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment