authorize method

Future<String> authorize({
  1. String? clientId,
  2. required 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? codeVerifier,
  10. String? nonce,
  11. String? kauthTxId,
  12. bool webPopupLogin = false,
})

KO: 카카오계정으로 로그인: 리다이렉트 방식
EN: Login with Kakao Account through redirection

Implementation

Future<String> authorize({
  String? clientId,
  required String redirectUri,
  List<String>? scopes,
  String? agt,
  List<String>? channelPublicIds,
  List<String>? serviceTerms,
  List<Prompt>? prompts,
  String? loginHint,
  String? codeVerifier,
  String? nonce,
  String? kauthTxId,
  bool webPopupLogin = false,
}) async {
  String? codeChallenge =
      codeVerifier != null ? _codeChallenge(codeVerifier) : null;
  final stateToken = generateRandomString(20);
  final kaHeader = await KakaoSdk.kaHeader;

  final params = await _makeAuthParams(
    clientId: clientId,
    redirectUri: redirectUri,
    scopes: scopes,
    agt: agt,
    channelPublicIds: channelPublicIds,
    serviceTerms: serviceTerms,
    prompts: prompts,
    loginHint: loginHint,
    codeChallenge: codeChallenge,
    nonce: nonce,
    kauthTxId: kauthTxId,
    stateToken: stateToken,
    isPopup: webPopupLogin,
  );
  final url = Uri.https(KakaoSdk.hosts.kauth, Constants.authorizePath, {
    ...params,
    Constants.isPopup: '$webPopupLogin',
  });
  SdkLog.i(url);

  try {
    if (kIsWeb && webPopupLogin) {
      final additionalParams = {};

      if (isiOS()) {
        additionalParams.addAll({
          ...params,
          'loginScheme': KakaoSdk.platforms.ios.talkLoginScheme,
          'universalLink': KakaoSdk.platforms.ios.iosLoginUniversalLink,
        });
      }

      await _channel.invokeMethod('popupLogin', {
        'url': url.toString(),
        ...additionalParams,
      });
      return _getAuthCode(stateToken, kaHeader);
    } else {
      final authCode = await _channel.invokeMethod('accountLogin', {
        CommonConstants.url: url.toString(),
        CommonConstants.redirectUri: redirectUri,
      });
      return _parseCode(authCode);
    }
  } catch (e) {
    SdkLog.e(e);
    rethrow;
  }
}