request method
Requests authorization code via Chrome Custom Tabs
(on Android) and ASWebAuthenticationSession
(on iOS).
Implementation
Future<String> request(
{String? clientId,
String? redirectUri,
String? codeVerifier,
List<Prompt>? prompts,
List<String>? scopes,
String? state}) async {
final finalRedirectUri = redirectUri ?? "kakao${_platformKey()}://oauth";
var codeChallenge;
if (codeVerifier != null) {
codeChallenge =
base64.encode(sha256.convert(utf8.encode(codeVerifier)).bytes);
}
final params = {
"client_id": clientId ?? _platformKey(),
"redirect_uri": finalRedirectUri,
"response_type": "code",
// "approval_type": "individual",
"scope": scopes == null ? null : scopes.join(" "),
"prompt": state == null
? (prompts == null ? null : parsePrompts(prompts))
: parsePrompts(_makeCertPrompts(prompts)),
"state": state == null ? null : state,
"codeChallenge": codeChallenge,
"codeChallengeMethod": codeChallenge != null ? "S256" : null,
"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);
}