requestTemporaryCredentials method

Future<AuthorizationResponse> requestTemporaryCredentials([
  1. String? callbackURI
])

Obtain a set of temporary credentials from the server. http://tools.ietf.org/html/rfc5849#section-2.1

If not callbackURI passed, authentication becomes PIN-based.

Implementation

Future<AuthorizationResponse> requestTemporaryCredentials(
    [String? callbackURI]) async {
  callbackURI ??= 'oob';
  final Map<String, String> additionalParams = <String, String>{
    'oauth_callback': callbackURI
  };
  final AuthorizationHeaderBuilder ahb = AuthorizationHeaderBuilder();
  ahb.signatureMethod = _platform.signatureMethod;
  ahb.clientCredentials = _clientCredentials;
  ahb.method = 'POST';
  ahb.url = _platform.temporaryCredentialsRequestURI;
  ahb.additionalParameters = additionalParams;

  final http.Response res = await _httpClient.post(
      Uri.parse(_platform.temporaryCredentialsRequestURI),
      headers: <String, String>{'Authorization': ahb.build().toString()});

  if (res.statusCode != 200) {
    throw StateError(res.body);
  }

  final Map<String, String> params = Uri.splitQueryString(res.body);
  final String? confirmed = params['oauth_callback_confirmed'];
  if (confirmed != 'true' && confirmed != '1') {
    throw StateError('oauth_callback_confirmed must be true');
  }

  return AuthorizationResponse.fromMap(params);
}