flutter_naver_login

Build Status Build Status Build Status Build Status Build Status

A Flutter plugin for using the native Naver Login SDKs on Android and iOS.

AndroidX support

Installation

To get things up and running, you'll have to declare a pubspec dependency in your Flutter project. Also some minimal Android & iOS specific configuration must be done, otherise your app will crash.

On your Flutter project

See the installation instructions on pub.

Android

This assume that you have performed the "link app to package name and base class the Naver Login documentation for Android site.

Your Application Info is shown in the for Naver Developer Website.

Then find out what the Client ID is. The Naver Client ID can be found on the Naver App Dashboard from the Naver Developer Console.

Once you find out your Naver Client ID, URL Scheme and Set Package Name you'll have to do some things.

Then simply copy and paste into ROOT.

<your project root>android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="client_id">[client_id]</string>
    <string name="client_secret">[client_secret]</string>
    <string name="client_name">[client_name]</string>
</resources>

<your project root>android/app/src/main/AndroidManifest.xml

 <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="flutter_naver_login_example"
        android:icon="@mipmap/ic_launcher">
        <meta-data
            android:name="com.naver.sdk.clientId"
            android:value="@string/client_id" />
        <meta-data
            android:name="com.naver.sdk.clientSecret"
            android:value="@string/client_secret" />
         <meta-data
            android:name="com.naver.sdk.clientName"
            android:value="@string/client_name" />
			...

A sample of the file can be found here. here.

Done!

iOS

Cocoapod

<your project root>ios/

pod install

This assumes that you've done the "Register and Configure Your App with Naver" step in the the Naver Login documentation for iOS site. (Note: you can skip "Step 2: Set up Your Development Environment").

After you've done that, find out what your Naver App Client ID is. You can find your Client ID, Client Secret, URL_SCHEME, in your Naver App's dashboard in the Naver developer.

<your project root>ios/Runner/Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
				<!-- other codes -->
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>[UrlScheme]</string>
                </array>
            </dict>
        </array>
  
        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>naversearchapp</string>
            <string>naversearchthirdlogin</string>
        </array>
        <key>kServiceAppUrlScheme</key>
        <string>[UrlScheme]</string>
        <key>kConsumerKey</key>
        <string>[ConsumerKey]</string>
        <key>kConsumerSecret</key>
        <string>[ConsumerSecret]</string>
        <key>kServiceAppName</key>
        <string>[ServiceAppName]</string>
        
        <!-- http allows configurations -->
        <key>NSAppTransportSecurity</key>
        <dict>
           <key>NSAllowsArbitraryLoads</key>
           <true/>
           <key>NSExceptionDomains</key>
           <dict>
              <key>naver.com</key>
              <dict>
                 <key>NSExceptionAllowsInsecureHTTPLoads</key>
                 <true/>
                 <key>NSExceptionRequiresForwardSecrecy</key>
                 <false/>
                 <key>NSIncludesSubdomains</key>
                 <true/>
              </dict>
              <key>naver.net</key>
              <dict>
                 <key>NSExceptionAllowsInsecureHTTPLoads</key>
                 <true/>
                 <key>NSExceptionRequiresForwardSecrecy</key>
                 <false/>
                 <key>NSIncludesSubdomains</key>
                 <true/>
              </dict>
           </dict>
        </dict>
    </dict>
</plist>

A sample of a complete Info.plist file can be found here.

Add the following code to log in using the Naver app. <your project root>ios/Runner/ios/Runner/AppDelegate.m

object-c

// Implemented when iOS 9.0 Less
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[NaverThirdPartyLoginConnection getSharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

// Implemented when iOS 9.0 higher

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    return [[NaverThirdPartyLoginConnection getSharedInstance] application:app openURL:url options:options];
}

swift

 override func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return NaverThirdPartyLoginConnection.getSharedInstance().application(app, open: url, options: options)
    }

How do I use it?

The library tries to closely match the native Android & iOS login SDK APIs where possible. For complete API documentation, just see the source code. Everything is documented there.

Since sample code is worth more than one page of documentation, here are the usual cases covered:

Getting the Naver acccount of a signed in user

NaverLoginResult res = await FlutterNaverLogin.logIn();
setState(() {
    name = res.account.name;
});

The account variable will now contain the following information:

final String nickname;
final String id;
final String name;
final String email;
final String gender;
final String age;
final String birthday;
final String profileImage;

Getting the Naver currentAccessToken of a signed in user

import 'package:flutter_naver_login/flutter_naver_login.dart';

NaverLoginResult res = await FlutterNaverLogin.logIn();
final NaverLoginResult result = await FlutterNaverLogin.logIn();
NaverAccessToken res = await FlutterNaverLogin.currentAccessToken;
setState(() {
   accesToken = res.accessToken;
   tokenType = res.tokenType;
});

ios issue

  1. CocoaPods could not find compatible versions for pod "naveridlogin-sdk-ios" Specs satisfying the naveridlogin-sdk-ios (~> 4.0.12) dependency were found, but they required a higher minimum deployment target.
    • runner target - required a higher deployment target 10.0.
  2. d: warning: directory not found for option '-L/project directory' ld: library not found for -lflutter_naver_login clang: error: linker command failed with exit code 1 (use -v to see invocation)
    • build - clean - commandRun: flutter run
  3. Showing All Messages: Multiple commands produce '/Users/yoonjaepark/dev/my_app/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework':
    • file - project settings - build system - legacy build system

Libraries

flutter_naver_login