<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는 그냥 은행에 가서 중개인한테 위임하고 싶다고 하니까 은행에서 토큰을 준다. 이 토큰을 중개인한테 주면서 이 토큰을 쓰면 아마 될거야 라고 한다. 중개인은 진짜 되나? 확인하려고 은행에 토큰 주고 신뢰받으면 중개인과 통신??(은행을 검증하는 용도로 사용)
void kakaoLogin() async{
try {
// 1. 크리덴셜 로그인 - 토근 받기
OAuthToken token = await UserApi.instance
.loginWithKakaoAccount();
// qRR-UeowO-LEp0_KXAGH41vyG64QiCkJAAAAAQopyV8AAAGP3Jb1gxamEcnPBcmr
print('카카오톡으로 로그인 성공 ${token.accessToken}');
// 2. 토큰(카카오)을 스프링 서버에 전달하기 (스프링 서버에게 나 인증했어! 라고 알려주는 과졍)
// 3. 토큰(스프링 서버) 응답 받기
// 4. 시큐어 스토리지에 저장
} catch (error) {
print('카카오톡으로 로그인 실패 $error');
}
}
이제 토큰을 스프링 서버에게 전달해보자.
3. 고객한테 받은 토큰을 카카오에 던져 검증하기
token.해보면 위 항목들이 있다.
이게 회원정보 요청하는 코드다.
stl이라서 토큰만 탈취하면 정보 얻는게 가능해진다.
서버
package shop.mtcoding.blog.user;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.sql.Timestamp;
public class KakaoResponse {
@Data
public static class KakaoUserDTO {
private Long id;
@JsonProperty("connected_at")
private Timestamp connectedAt;
private Properties properties;
@Data
class Properties {
private String nickname;
}
}
}
/user/KakaoResponse.java
flutter(androidstudio)
내 로컬 주소 넣기
📌
baseUrl에 내 IP를 넣어야 한다.
서버2
사용자 정보DTO 코드 넣기
서버에 토큰 던지기
개념 재적립
코드방식: 중개인이 주인에게 받은 코드를 은행에 가져갔을 때 토큰을 받는다.
우리가 적용한 코드에 크리데셜:클라이언트가 은행에 토큰을 직접 받고 중개인에게 토큰을 넘겨주는 시스템 중개인이 다시 대체 토큰을 발행해서 클라이언트에게 준다.(이유는 이렇게안하면 중개인이 매번 은행에가서 클라이언트에게서 받은 토큰이 은행 토큰인지 검증해야 하기 때문이다)
잡혀있어야 하는 개념
해시
전자서명
토큰
토큰은 서버가 상태를 안 가져도 된다.
해시는 임의의 16진수 난수이며 고정길이를 가진다.
해시는 불변이나 변화 감지할 때 쓰인다.
해시값을 공인된 기관에 등록해야 해시.
그래야 검사할 때 공인된 기관에서 들고와서 검증이 가능하기 때문에
전자서명: 원본(해쉬) ≠ 복제(해쉬)
해시는 암호화를 위해 쓰는게 아니다 .전자 서명을 위해 쓰는거다.
웹 자체는 stateless 기반이다. 그래서 중요한 정보를 요청할 때마다 로그인하고 응답받아야 한다. 응답 받고 나서 그 다음에 요청하면 기억 못해서 다른 사람이 요청한다고 생각한다.