import { Component } from '@angular/core';
import * as uuid from 'uuid';
import * as jose from 'node-jose';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'my-app';
ngOnInit() {
// load the key in PEM format
let key = (...YOUR_PRIVATE_KEY_PEM...);
// generating the token
let token = {
sub: "YOUR_CLIENT_ID",
aud: "https://AAAS_PLATFORM/idp/YOUR_TENANT/authn/token",
nbf: Math.floor(Date.now() / 1000) - 30,
iss: "YOUR_CLIENT_ID",
exp: Math.floor(Date.now() / 1000) + (60 * 60),
jti: uuid.v1(),
iat: Math.floor(Date.now() / 1000) - 30
};
jose.JWK.asKey(key, "pem").then(function(jwk) {
console.log(jwk);
var signature =
jose.JWS.createSign({
alg: "RS256",
format: 'compact'
}, jwk).
update(JSON.stringify(token), "utf8").
final();
// signing
signature.then(function(result) {
// result contains the token ready to send to the Authentication Service
console.log(result);
}, function(error) {
console.log(error);
});
});
}
}