GAuth SDK 사용법 - Android
‣
담당자 - 김현승#3508
0. 디펜던시 추가
project의 app단위 그레들에
implementation 'com.github.GSM-MSG:GAuth-Signin-Android:v1.0.7'
을 추가합니다
settings.gradle에
maven { url 'https://jitpack.io' }
도 추가해줍니다.
1. 웹뷰 띄우기 (code 발급)
GAuthSigninWebView
메서드에 파라미터로
clientId: String
redirectUri: String
넣어 웹뷰를 호출합니다.
ex)
GAuthSigninWebView(
clientId = "클아이언트 아이디",
redirectUri = "리다이렉트 uri"
) { response ->
//response로 코드 값을 받을 수 있습니다.
}
2. 토큰 발급
GAuth오브젝트 안의 getGAuthTokenRequest
메서드에 파라미터로
code: String,
clientId: String,
clientSecret: String,
redirectUri: String
을 넣어 호출합니다.
ex)
GAuth.getGAuthTokenRequest(
code = "코드",
clientSecret = "시크릿",
clientId = "아이디",
redirectUri = "유알앨"
) { response ->
//response로 스테이터스와 토큰에 대한 정보를 받을 수 있습니다.
}
3. 토큰 재발급
GAuth오브젝트 안의 tokenRefreshRequest
메서드에 파라미터로
refreshToken: String
을 넣어 호출합니다.
ex)
GAuth.tokenRefreshRequest(
refreshToken = "토큰"
) { response->
// response로 스테이터스와 토큰에 대한 정보를 받을 수 있습니다.
}
4. 유저 정보 가져오기
GAuth오브젝트 안의 getUserInfoRequest
메서드에 파라미터로
accessToken: String
을 넣어 호출합니다.
ex)
GAuth.getUserInfoRequest(
accessToken = "토큰"
) { response ->
// response로 스테이터스와 유저에 대한 정보를 받을 수 있습니다.
}
5. API로 코드 받기
GAuth오브젝트 안의 getCodeInfoRequest
메서드에 파라미터로
email: String,
password: String
을 넣어 호출합니다.
ex)
GAuth.getCodeInfoRequest(
email = "이멜",
password = "패스워드"
) { response ->
// response로 스테이터스와 코드값을 받을 수 있습니다.
}
0. GAuth 버튼 사용법
GAuthButton(
style = ,
actionType = ,
colors = ,
horizontalPaddingValue:Dp? = ,
horizontalPercent: Float? = ,
horizontalMargin: Dp? = ,
){
//onClick시에 동작할 코드
}
GAuthButton 컴포저블을 호출한 후에 코드에서 보이는 것처럼 각 파라미터에 Type을 넣어 모양과 색상을 변경하여 사용할 수 있습니다.
- horizontalPaddingValue에 dp값을 넣어 가로 길이를 조절할 수 있습니다.
GAuthButton(
style = Types.Style.ROUNDED,
actionType = Types.ActionType.SIGNIN,
colors = Types.Colors.OUTLINE,
horizontalPaddingValue = 70.dp
){
}
- horizontalPercent에 float값을 넣어 가로길이를 퍼센트로 조절할 수 있습니다. ex) 0.9f → 90%
GAuthButton(
style = Types.Style.ROUNDED,
actionType = Types.ActionType.SIGNIN,
colors = Types.Colors.OUTLINE,
horizontalPercent = 0.9f
){
}
- horizontalMargin에 dp값을 넣어 가로길이를 조절할 수 있습니다.
GAuthButton(
style = Types.Style.ROUNDED,
actionType = Types.ActionType.SIGNIN,
colors = Types.Colors.OUTLINE,
horizontalMargin = 20.dp
){
}
- 스타일 가이드
- 버튼 컴포넌트 디폴트값
fun GAuthButton(
style: Types.Style = Types.Style.DEFAULT,
actionType: Types.ActionType = Types.ActionType.SIGNIN,
colors: Types.Colors = Types.Colors.WHITE,
horizontalPaddingValue: Dp? = null,
horizontalPercent: Float? = null,
horizontalMargin: Dp? = null,
onClick: () -> Unit
) {
...
}
예시코드)
GAuthButton(
style = Types.Style.DEFAULT,
actionType = Types.ActionType.SIGNIN,
colors = Types.Colors.OUTLINE,
horizontalPaddingValue = 50.dp
){
Log.d("GAuth","GAuth")
}
추가 사항
GAuthButton은 Compose로 구성되어 있으므로 xml에서 사용하고 싶을 경우에는 그레이들에 Compose관련 그레이들을 모두 추가한 이후 xml상에서 ComposeView를 만들고 뷰에 접근한 다음 setContent를 이용해 버튼을 사용할 수 있습니다.
에시코드)
ComposeView
<androidx.compose.ui.platform.ComposeView
android:id="@+id/signInBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/guideline21"/>
setContent
binding.signInBtn.setContent{
GAuthButton(
style = Types.Style.DEFAULT,
actionType = Types.ActionType.SIGNIN,
colors = Types.Colors.OUTLINE,
horizontalPaddingValue = (dpWidth / 2 - 120).dp
){
//TODO
}
}