authorize method Null safety

Future<String> authorize(
  1. {String? clientId,
  2. String? redirectUri,
  3. List<String>? scopes,
  4. String? agt,
  5. List<String>? channelPublicIds,
  6. List<String>? serviceTerms,
  7. List<Prompt>? prompts,
  8. String? loginHint,
  9. String? state,
  10. String? codeVerifier,
  11. String? nonce,
  12. bool webPopupLogin = false}
)

사용자가 앱에 로그인할 수 있도록 인가 코드를 요청하는 함수입니다. 인가 코드를 받을 수 있는 서버 개발이 필요합니다.

Implementation

Future<String> authorize({
  String? clientId,
  String? redirectUri,
  List<String>? scopes,
  String? agt,
  List<String>? channelPublicIds,
  List<String>? serviceTerms,
  List<Prompt>? prompts,
  String? loginHint,
  String? state,
  String? codeVerifier,
  String? nonce,
  bool webPopupLogin = false,
}) async {
  final finalRedirectUri = redirectUri ?? "kakao${_platformKey()}://oauth";
  String? codeChallenge = codeVerifier != null
      ? base64.encode(sha256.convert(utf8.encode(codeVerifier)).bytes)
      : null;
  final params = {
    Constants.clientId: clientId ?? _platformKey(),
    Constants.redirectUri: finalRedirectUri,
    Constants.responseType: Constants.code,
    // "approval_type": "individual",
    Constants.scope: scopes?.join(" "),
    Constants.agt: agt,
    Constants.channelPublicId: channelPublicIds?.join(','),
    Constants.serviceTerms: serviceTerms?.join(','),
    Constants.prompt: state == null
        ? (prompts == null ? null : _parsePrompts(prompts))
        : _parsePrompts(_makeCertPrompts(prompts)),
    Constants.loginHint: loginHint,
    Constants.state: state,
    Constants.codeChallenge: codeChallenge,
    Constants.codeChallengeMethod:
        codeChallenge != null ? Constants.codeChallengeMethodValue : null,
    Constants.kaHeader: await KakaoSdk.kaHeader,
    Constants.nonce: nonce,
  };
  params.removeWhere((k, v) => v == null);
  final url =
      Uri.https(KakaoSdk.hosts.kauth, Constants.authorizePath, params);
  SdkLog.i(url);

  try {
    final authCode = await launchBrowserTab(
      url,
      redirectUri: finalRedirectUri,
      popupOpen: webPopupLogin,
    );

    return _parseCode(authCode);
  } catch (e) {
    SdkLog.e(e);
    rethrow;
  }
}