getTokens static method

Future<TokenPair> getTokens(
  1. String resourceUrl,
  2. String method
)

Get access token and DPoP token for a resource URL.

resourceUrl - The URL of the resource to access. method - HTTP method (GET, PUT, POST, DELETE).

Implementation

static Future<TokenPair> getTokens(String resourceUrl, String method) async {
  final authData = await AuthDataManager.loadAuthData();
  if (authData == null) {
    throw Exception('Not authenticated - please log in first');
  }

  final accessToken = authData['accessToken'] as String;
  final rsaInfo = authData['rsaInfo'] as Map;
  final rsaKeyPair = rsaInfo['rsa'];
  final publicKeyJwk = rsaInfo['pubKeyJwk'];

  final dPopToken = genDpopToken(
    resourceUrl,
    rsaKeyPair,
    publicKeyJwk,
    method,
  );

  return (accessToken: accessToken, dPopToken: dPopToken);
}