request method

Future<String> request({
  1. String? clientId,
  2. String? redirectUri,
  3. List<Prompt>? prompts,
  4. List<String>? scopes,
})

Requests authorization code via Chrome Custom Tabs (on Android) and ASWebAuthenticationSession (on iOS).

Implementation

Future<String> request(
    {String? clientId,
    String? redirectUri,
    List<Prompt>? prompts,
    List<String>? scopes}) async {
  final finalRedirectUri = redirectUri ?? "kakao${_platformKey()}://oauth";

  final params = {
    "client_id": clientId ?? _platformKey(),
    "redirect_uri": finalRedirectUri,
    "response_type": "code",
    "approval_type": "individual",
    "scope": scopes == null ? null : scopes.join(" "),
    "prompt": prompts == null
        ? null
        : describeEnum(prompts.join(" ")).toLowerCase(),
    "ka": await KakaoContext.kaHeader
  };
  params.removeWhere((k, v) => v == null);
  final url = Uri.https(KakaoContext.hosts.kauth, "/oauth/authorize", params);
  final authCode = await launchBrowserTab(url, redirectUri: finalRedirectUri);
  return _parseCode(authCode);
}