Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
openssl req -x509 -new -nodes -sha256 -days 720 \
-key fileName.key.pem -out fileName.cert.pem




















const fs = require('fs')
const path = require('path')
const jwt = require('jsonwebtoken')
const request = require('request')
// settings
const basePath = 'https://identityhomolog.acesso.io'
// entry point
let options = {
serviceAccount: 'svcapp1',
tenant: "9ea3c3bd-4447-4c3b-ae2e-504b795d3733"
}
requestAnAccessToken(createServiceAccountToken(options), (err, accessToken) => {
let payload = jwt.decode(accessToken.access_token)
console.log('Response:')
console.log(' Access Token: ', accessToken.access_token)
console.log(' ID: ', payload.jti)
console.log(' Issuer: ', payload.iss)
console.log(' Subject: ', payload.sub)
console.log(' expires_in: ', accessToken.expires_in)
console.log(' Expiration Date: ', new Date(payload.exp))
console.log(' Creation Date: ', new Date(payload.iat))
})
// functions
function createServiceAccountToken({tenant, serviceAccount, account = ''}) {
// Reads the service account private key
let privateKey = fs.readFileSync(path.resolve(`${serviceAccount}.key.pem`))
// Prepare the request
let payload = {
iss: `${serviceAccount}@${tenant}.iam.acesso.io`,
aud: basePath,
scope: '*',
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(Date.now() / 1000)
}
// Service account is requesting an access token for another user?
if (account) {
payload.sub = account
}
// Create JWS
return jwt.sign(payload, privateKey, { algorithm: 'RS256' })
}
function requestAnAccessToken(serviceToken, callback) {
// Prepare the request
let options = {
method: 'POST',
url: `${basePath}/oauth2/token`,
headers: {'content-type': 'application/x-www-form-urlencoded'},
form: {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer' ,
assertion: serviceToken
}
}
console.log('Requesting Access Token with self created token:' )
console.log('', serviceToken)
// Ask identity and authorization server for an access token
request(options, (error, response, body) => {
if (error) {
callback(new Error(error))
}
body = JSON.parse(body)
if (body.error) {
callback(new Error(`${body.error}: ${body.error_description}`))
}
callback(null, body)
})
}{
"error": "server_error",
"error_description": "Falha na autenticação x.x.x"
}{Cabeçalho em Base64url}.{Payload em Base64url}.{Assinatura em Base64url}{Cabeçalho em Base64url}.{Payload em Base64url}{"alg":"RS256","typ":"JWT"}eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9exp = iat + 3600{
"iss": "service_account_name@tenant_id.iam.acesso.io",
"aud": "https://identityhomolog.acesso.io",
"scope": "*",
"exp": 1626296976, // Este é apenas um exemplo. Utilize aqui o valor atual gerado.
"iat": 1626293376 // Este é apenas um exemplo. Utilize aqui o valor atual gerado.
}{Cabeçalho em Base64url}.{Payload em Base64url}{Cabeçalho em Base64url}.{Payload em Base64url}.{Assinatura em Base64url}{"alg":"RS256","typ":"JWT"}.
{
"iss": "service_account_name@tenant_id.iam.acesso.io",
"aud": "https://identityhomolog.acesso.io",
"scope": "*",
"exp": 1626296976, // Este é apenas um exemplo. Utilize aqui o valor atual gerado.
"iat": 1626293376 // Este é apenas um exemplo. Utilize aqui o valor atual gerado.
}.
[byte array da assinatura]eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzZXJ2aWNlX2FjY291bnRf
bmFtZUB0ZW5hbnRfaWQuaWFtLmFjZXNzby5pbyIsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHlob21vbG9nLmFjZXNzby5pbyIsInNjb
3BlIjoiKiIsImV4cCI6MTYyNjI5Njk3NiwiaWF0IjoxNjI2MjkzMzc2fQ.JsymP3NZdgCSqeNlgsOM2
-AQ7M450NxFnZnnaKSu4Q8g12QGEIvvM4EhCokUHfwk5s7pOpm2UD_Ng3Hb5g_wgrjfiVSLWH5Q2wYg1AvfLqo
YSoJWaMHm9KL0kpv32XdDD8TZVR-MVd2VBHmCMVbV6gvk8buUoK1HZDN7g84PaY3bfgcB3RKU-
H55lR8yyJjZxToIv17-wfla2G99uaMEFNGX0ZSE7ETn5Z8-WypmFrNAK0TM58upzvfVI6_-
gY4cj4iQvmRbuvxsAaGiHA2xd0RVm2Mrx-gQtdPqtbZPuQcH7k64Z_EOQBgiGTgVjucyHD6zBijr_P-
2mhIxuecNSwhttps://identityhomolog.acesso.io/oauth2/tokenPOST /oauth2/token HTTP/1.1
Host: identityhomolog.acesso.io
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-
bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzZXJ2aWNlX2FjY
291bnRfbmFtZUB0ZW5hbnRfaWQuaWFtLmFjZXNzby5pbyIsInN1YiI6InVzZXJfaWRlbnRpZmllciIs
ImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHlob21vbG9nLmFjZXNzby5pbyIsInNjb3BlIjoiKiIsImV4cCI
6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ.TjH-mTtwP6tBB93O1sDPaAA6yUF7N2-HZDlpIPz
bf_dxO8A6KZuRWG8ZnICrxX56qj0HREiMlYy27XJgxowrUa0JHvbqc8HJkT7-6Mh7J67UnubZKG1-hi
6jDtkC9BIXBcOhtkNUfZvZetXjLzsRsSDkqxdMtzYZwkRlocvaxL5QXiQhweeEwK_Ux81Adh3z0EIhT
yl7CKJLJ69PuHS7s9IdrjUl79owipp4LF1FvtMhoe7YIL69ohPgFqSv_-Y9qpPdW6be3OEAyKlOM08S
ZBbHBwW4XMvw3uZjTY1sgJ4cBoxrftDpjYOw34oPOKxirqc5-90uOCYe1O1hRtG45w{
"access_token": "<access_token>",
"token_type": "Bearer",
"expires_in": "3600"
}token decodificado:
new Date(token.exp - 600)Cenário padrão:
expires_in: 3600 (1h) - Geração do token as 14h42
Solicitar um novo token somente as 15h32 ou seja, 14:42 + (3600 - 600)Cenário com a duração alterada:
expires_in: 7200 (2h) - Geração do token as 14h42
Solicitar um novo token somente as 16h32 ou seja, 14:42 + (7200 - 600)
<EntityDescriptor entityID="https://your-sp.example.com/" xmlns="urn:oasis:names:tc:SAML:2.0:metadata">
<SPSSODescriptor
AuthnRequestsSigned="true"
protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<KeyDescriptor use="signing">
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
<X509Certificate>YourSigningCertificate</X509Certificate>
</X509Data>
</KeyInfo>
</KeyDescriptor>
<AssertionConsumerService
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://your-sp.example.com/acs"
index="1"/>
</SPSSODescriptor>
</EntityDescriptor>