Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

외부에서 CookieJar 주입할 수 있도록 수정 #10

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion android-demoapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId 'com.ridi.oauth2.demoapp'
minSdkVersion 15
minSdkVersion 26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

흠.. min sdk 가 안드 앱의 min sdk 보다 높은데 이 부분이 특별히 문제가 되진 않겠죠? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넴, 데모 앱 세팅을 전반적으로 바꿔야 하는데 여러모로 손이 가서 IDE가 원하는대로 해줬어요 (..)

targetSdkVersion 29
versionCode 1
versionName '1.0'
Expand All @@ -28,6 +28,7 @@ android {
dependencies {
implementation project(':library')
implementation 'com.auth0.android:jwtdecode:2.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainActivity : Activity() {
val devMode = switch.isChecked.not()
val username = findViewById<TextView>(R.id.username).text.toString()
val password = findViewById<TextView>(R.id.password).text.toString()
val authorization = Authorization(clientId, clientSecret, devMode)
val authorization = Authorization(clientId, clientSecret, devMode = devMode)
authorization.requestPasswordGrantAuthorization(username, password).subscribe(TokenObserver(authorization))
}
}
Expand Down
9 changes: 8 additions & 1 deletion library/src/main/kotlin/com/ridi/oauth2/Authorization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import com.google.gson.JsonSyntaxException
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleEmitter
import java.util.concurrent.TimeUnit
import okhttp3.CookieJar
import okhttp3.OkHttpClient
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class Authorization(private val clientId: String, private val clientSecret: String, devMode: Boolean = false) {
class Authorization(
private val clientId: String,
private val clientSecret: String,
private val cookieJar: CookieJar? = null,
devMode: Boolean = false
) {
companion object {
private const val DEV_HOST = "account.dev.ridi.io"
private const val REAL_HOST = "account.ridibooks.com"
Expand All @@ -30,6 +36,7 @@ class Authorization(private val clientId: String, private val clientSecret: Stri
val client = OkHttpClient.Builder()
.connectTimeout(CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.apply { cookieJar?.let { cookieJar(it) } }
.build()
val retrofit = Retrofit.Builder()
.client(client)
Expand Down