<activityandroid:name="com.kakao.sdk.flutter.AuthCodeCustomTabsActivity"android:exported="true"><intent-filterandroid:label="flutter_web_auth"><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.DEFAULT" /><categoryandroid:name="android.intent.category.BROWSABLE" /><!-- "kakao${YOUR_NATIVE_APP_KEY}://oauth" 형식의 앱 실행 스킴 설정 --><!-- 카카오 로그인 Redirect URI --><dataandroid:scheme="kakaobb232a2ba1ad3806f117271ac8122d96"android:host="oauth"/></intent-filter></activity>
AndroidManifest.xml에 위 코드를 추가한다.
앞의 kakao는 그대로 두고 표시한 부분에 나의 네이티브 앱 키를 넣는다.
5.카카오 크리덴셜 로그인 방식 사용
5.1 버전 21이상으로 잡기
❗
JAVA(21)버전 부터 권한에 대한 체크를 안하면 앱이 안돌아가게끔 설정이 돼있다.
외부 라이브러리 = 서드 파티 라이브러리
5.2 카카오 로그인 활성화
5.3 동의 항목 설정 및 카카오 로그인 활성화
5.4 코드
import'package:flutter/material.dart';
import'package:flutter_riverpod/flutter_riverpod.dart';
import'package:kakao_flutter_sdk/kakao_flutter_sdk.dart';
import'package:oauthapp/_core/move.dart';
import'ui/login_page/login_page.dart';
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
void main() {
WidgetsFlutterBinding.ensureInitialized();
// runApp() 호출 전 Flutter SDK 초기화
KakaoSdk.init(
// 웹 환경에서 카카오 로그인을 정상적으로 완료하려면 runApp() 호출 전 아래 메서드 호출 필요
nativeAppKey: '32aabd0174910c36860841fa57583ef7'
);
// runApp() 호출 전 Flutter SDK 초기화
runApp(ProviderScope(child: MyApp()));
}
classMyAppextendsStatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
home: LoginPage(),
routes: getRouters(),
);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="oauthapp"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name="com.kakao.sdk.flutter.AuthCodeCustomTabsActivity"
android:exported="true">
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- "kakao${YOUR_NATIVE_APP_KEY}://oauth" 형식의 앱 실행 스킴 설정 -->
<!-- 카카오 로그인 Redirect URI -->
<data android:scheme="kakao51954f8d3d73cbf57597140dbcbee7f6" android:host="oauth"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility?hl=en and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
성공하면 밑에 access token이 뜨는데 이걸 secureStorage에 저장해야 한다.
개념
클라이언트 프로그램에 토큰을 주는 것의 여부에 따라 코드 방식인지 아닌지 갈린다.
이번에 한 OAuth는 그냥 은행에 가서 중개인한테 위임하고 싶다고 하니까 은행에서 토큰을 준다. 이 토큰을 중개인한테 주면서 이 토큰을 쓰면 아마 될거야 라고 한다. 중개인은 진짜 되나? 확인하려고 은행에 토큰 주고 신뢰받으면 중개인과 통신??(은행을 검증하는 용도로 사용)
우리가 적용한 코드에 크리데셜:클라이언트가 은행에 토큰을 직접 받고 중개인에게 토큰을 넘겨주는 시스템 중개인이 다시 대체 토큰을 발행해서 클라이언트에게 준다.(이유는 이렇게안하면 중개인이 매번 은행에가서 클라이언트에게서 받은 토큰이 은행 토큰인지 검증해야 하기 때문이다)
잡혀있어야 하는 개념
해시
전자서명
토큰
토큰은 서버가 상태를 안 가져도 된다.
해시는 임의의 16진수 난수이며 고정길이를 가진다.
해시는 불변이나 변화 감지할 때 쓰인다.
해시값을 공인된 기관에 등록해야 해시.
그래야 검사할 때 공인된 기관에서 들고와서 검증이 가능하기 때문에
전자서명: 원본(해쉬) ≠ 복제(해쉬)
해시는 암호화를 위해 쓰는게 아니다 .전자 서명을 위해 쓰는거다.
웹 자체는 stateless 기반이다. 그래서 중요한 정보를 요청할 때마다 로그인하고 응답받아야 한다. 응답 받고 나서 그 다음에 요청하면 기억 못해서 다른 사람이 요청한다고 생각한다.