> For the complete documentation index, see [llms.txt](https://developer.aliothx.net/start/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.aliothx.net/start/common/index/authentification.md).

# 인증 연동

인증 및 연동은 모바일 애플리케이션에서 매우 중요한 부분입니다. Flutter 애플리케이션에서 다양한 인증 방법을 통해 로그인하는 방법을 안내합니다. 이메일/비밀번호 인증, Google 로그인, KakaoTalk 로그인, Naver 로그인 및 Apple 로그인에 대해 알아보세요.&#x20;

## 이메일/비밀번호 인증

<div align="left"><figure><img src="/files/NXq2zEjf5jAjJZ7lwGNh" alt="" width="282"><figcaption></figcaption></figure> <figure><img src="/files/Zmm8uq6t4OxgkqVE63s9" alt="" width="283"><figcaption></figcaption></figure></div>

## SNS 로그인

<div align="left"><figure><img src="/files/ZqI87x89zts0vPwaDft9" alt=""><figcaption></figcaption></figure></div>

### Google&#x20;

`pubspec.yaml`에 `google_sign_in` 패키지를 추가하세요.

```yaml
yamlCopy codedependencies:
  google_sign_in: ^5.7.0
```

#### 구현 방법

`GoogleSignIn` 클래스를 사용하여 Google 로그인을 처리하세요. 코드에서 `_loginWithGoogle` 메서드를 확인하세요.

```dart
Future<void> _loginWithGoogle() async {
    try {
      await _googleSignIn.signIn();
      if (await GoogleSignIn().isSignedIn()) {
        UiUxData.navigatorKey!.currentContext
            ?.read<AuthService>()
            .isAuthenticated = true;
        widget.onLoginResult?.call(true);
        print('구글 로그인 성공');
      } else {
        print('구글 로그인 실패');
      }
    } catch (error) {
      print(error);
    }
  }
```

### KakaoTalk&#x20;

`pubspec.yaml`에 `kakao_flutter_sdk` 패키지를 추가하세요.

```yaml
yamlCopy codedependencies:
  kakao_flutter_sdk: ^0.10.0
```

#### 구현 방법

`kakao_flutter_sdk` 패키지의 `UserApi` 클래스를 사용하여 KakaoTalk 로그인을 처리하세요. 제공된 코드의 `_loginWithKakao` 메서드를 확인하세요.

```dart
Future<void> _loginWithKakao() async {
    if (await isKakaoTalkInstalled()) {
      try {
        await UserApi.instance.loginWithKakaoTalk();
        UiUxData.navigatorKey!.currentContext
            ?.read<AuthService>()
            .isAuthenticated = true;
        widget.onLoginResult?.call(true);
        print('카카오톡으로 로그인 성공');
      } catch (error) {
        print('카카오톡으로 로그인 실패 $error');

        if (error is PlatformException && error.code == 'CANCELED') {
          return;
        }

        try {
          await UserApi.instance.loginWithKakaoAccount();
          UiUxData.navigatorKey!.currentContext
              ?.read<AuthService>()
              .isAuthenticated = true;
          widget.onLoginResult?.call(true);
          print('카카오계정으로 로그인 성공');
        } catch (error) {
          print('카카오계정으로 로그인 실패 $error');
        }
      }
    } else {
      try {
        await UserApi.instance.loginWithKakaoAccount();
        UiUxData.navigatorKey!.currentContext
            ?.read<AuthService>()
            .isAuthenticated = true;
        widget.onLoginResult?.call(true);
        print('카카오계정으로 로그인 성공');
      } catch (error) {
        print('카카오계정으로 로그인 실패 $error');
      }
    }
  }
```

## Naver&#x20;

`pubspec.yaml`에 `flutter_naver_login` 패키지를 추가하세요.

```yaml
yamlCopy codedependencies:
  flutter_naver_login: ^4.0.0
```

#### 구현 방법

`FlutterNaverLogin` 클래스를 사용하여 Naver 로그인을 처리하세요. 코드에서 `_loginWithNaver` 메서드를 참조하세요.

```dart
Future<void> _loginWithNaver() async {
    try {
      await FlutterNaverLogin.logIn();
    } catch (error) {
      print(error);
    }

    NaverAccessToken res = await FlutterNaverLogin.currentAccessToken;

    if (res.accessToken != '') {
      UiUxData.navigatorKey!.currentContext
          ?.read<AuthService>()
          .isAuthenticated = true;
      widget.onLoginResult?.call(true);
      print('네이버 로그인 성공');
    } else if (res.accessToken == '') {
      print('네이버 로그인 실패');
    }
  }
```

## Apple&#x20;

`pubspec.yaml`에 `sign_in_with_apple` 패키지를 추가하세요.

```yaml
yamlCopy codedependencies:
  sign_in_with_apple: ^3.0.0
```

#### 구현 방법

`SignInWithApple` 클래스를 사용하여 Apple 로그인을 처리하세요. 코드에서 `_loginWithApple` 메서드를 확인하세요.

```dart
Future<UserCredential> _loginWithApple() async {
    final rawNonce = generateNonce();
    final nonce = sha256ofString(rawNonce);

    final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      webAuthenticationOptions: WebAuthenticationOptions(
        clientId: 'com.dubhesoft.aliothv2',
        redirectUri: Uri.parse(
            'https://flutter-sign-in-dc1ef.firebaseapp.com/__/auth/handler'),
      ),
      nonce: nonce,
    );

    final oauthCredential = OAuthProvider("apple.com").credential(
      idToken: appleCredential.identityToken,
      rawNonce: rawNonce,
    );

    return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
  }
```

Flutter 애플리케이션에서 다양한 인증 방법을 통해 로그인하는 방법을 제공합니다. 코드를 특정 사용 사례에 맞게 조정하고 각 라이브러리에서 제공하는 추가 설정 지침을 따라 앱 개발에 활용해보세요.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.aliothx.net/start/common/index/authentification.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
