generateAccessToken method

Future<Token> generateAccessToken({
  1. required String gateway,
  2. required String accessToken,
  3. required String privateKeyString,
})

Implementation

Future<Token> generateAccessToken(
    {required String gateway,
    required String accessToken,
    required String privateKeyString}) async {
  RubixServiceClient stub =
      getConnection(gateway: gateway, accessToken: accessToken);
  var resp = await stub.getAccessTokenChallenge(Empty());
  var challengeString = resp.challenge;
  var privateKey = KeyPair().privateKeyFromPem(privateKeyString);
  var signContent = Uint8List.fromList(challengeString.codeUnits);
  var pvtSign = KeyPair().keySignature(signContent, privateKey);
  var response = await stub.generateAccessToken(
      SignedPayload(payload: challengeString, signature: pvtSign));
  return response;
}