Solicitud de tokens correcta
This commit is contained in:
@@ -80,24 +80,24 @@ export class JWTToken<T> {
|
|||||||
}) {
|
}) {
|
||||||
const strHeader = JSON.stringify(args.header)
|
const strHeader = JSON.stringify(args.header)
|
||||||
const base64Header = Buffer.from(strHeader).toString("base64url")
|
const base64Header = Buffer.from(strHeader).toString("base64url")
|
||||||
let msg = base64Header
|
let token = base64Header
|
||||||
|
|
||||||
if (args.payload != undefined) {
|
if (args.payload != undefined) {
|
||||||
const strPayload = JSON.stringify(args.payload)
|
const strPayload = JSON.stringify(args.payload)
|
||||||
const base64payload = Buffer.from(strPayload).toString("base64url")
|
const base64payload = Buffer.from(strPayload).toString("base64url")
|
||||||
msg += ("." + base64payload)
|
token += ("." + base64payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.sigantureData != undefined) {
|
if (args.sigantureData != undefined) {
|
||||||
const base64signature = signJWT({
|
const base64signature = signJWT({
|
||||||
algorythm: args.sigantureData.algorythm,
|
algorythm: args.sigantureData.algorythm,
|
||||||
privateKey: args.sigantureData.privateKey,
|
privateKey: args.sigantureData.privateKey,
|
||||||
data: msg
|
data: token
|
||||||
}).toString("base64url")
|
}).toString("base64url")
|
||||||
msg += ("." + base64signature)
|
token += ("." + base64signature)
|
||||||
}
|
}
|
||||||
console.log("JWT", msg)
|
|
||||||
|
|
||||||
|
return token
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "#shared/domain/JWT"
|
} from "#shared/domain/JWT"
|
||||||
import axios, { AxiosError } from "axios";
|
import axios, { AxiosError } from "axios";
|
||||||
import { sign } from "node:crypto"
|
import { sign } from "node:crypto"
|
||||||
|
import { ClientRequest } from "node:http";
|
||||||
|
|
||||||
type GrantAccessRequestBody = {
|
type GrantAccessRequestBody = {
|
||||||
grant_type: string,
|
grant_type: string,
|
||||||
@@ -95,33 +96,40 @@ export class JWTService {
|
|||||||
console.warn("Se está intentado conseguir un token sin expirar el anterior")
|
console.warn("Se está intentado conseguir un token sin expirar el anterior")
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("headers", addIATHeaders(DEFAULT_HEADERS))
|
const httpheaders = addIATHeaders(DEFAULT_HEADERS)
|
||||||
console.log("body", DEFAULT_BODY)
|
const jwtHeaders = {
|
||||||
console.log("keypath", __dirname + "/../obj.pem")
|
alg: "RS256",
|
||||||
|
typ: "JWT",
|
||||||
|
kid: env.OBJ_KID
|
||||||
|
}
|
||||||
|
|
||||||
|
const jwtData = addIATHeaders({
|
||||||
|
sub: env.OBJ_CLIENT_ID,
|
||||||
|
iss: env.OBJ_CLIENT_ID,
|
||||||
|
aud: "https://idp.docapost.io/auth/realms/GETWAY",
|
||||||
|
jti: Date.now().toString(),
|
||||||
|
})
|
||||||
|
|
||||||
const key = fs.readFileSync(__dirname + "/../obj.pem", "utf8")
|
const key = fs.readFileSync(__dirname + "/../obj.pem", "utf8")
|
||||||
const msg = Buffer.from("test")
|
const token = JWTToken.fromParts({
|
||||||
const signature = sign(
|
header: jwtHeaders,
|
||||||
"sha256",
|
payload: jwtData,
|
||||||
Buffer.from(msg),
|
|
||||||
key
|
|
||||||
)
|
|
||||||
JWTToken.fromParts({
|
|
||||||
header: { alg: "RS256", typ: "JWT", kid: "1234" },
|
|
||||||
payload: {
|
|
||||||
"iss": "savefamily_rest_ws",
|
|
||||||
"aud": "https://idp.docapost.io/auth/realms/GETWAY",
|
|
||||||
},
|
|
||||||
sigantureData: {
|
sigantureData: {
|
||||||
algorythm: "sha256",
|
algorythm: "sha256",
|
||||||
privateKey: key
|
privateKey: key
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log("signature", signature.toString("base64url"))
|
const bodyWithtoken = {
|
||||||
|
...DEFAULT_BODY,
|
||||||
return;
|
client_assertion: token
|
||||||
|
}
|
||||||
|
console.log("body", bodyWithtoken)
|
||||||
|
|
||||||
const req = axios.post(GET_TOKEN_URL,
|
const req = axios.post(GET_TOKEN_URL,
|
||||||
DEFAULT_BODY,
|
{
|
||||||
|
...DEFAULT_BODY,
|
||||||
|
client_assertion: token
|
||||||
|
},
|
||||||
{
|
{
|
||||||
headers: addIATHeaders(DEFAULT_HEADERS)
|
headers: addIATHeaders(DEFAULT_HEADERS)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user