Skip to content

Commit

Permalink
Update auth library (#12)
Browse files Browse the repository at this point in the history
* Update version of omh auth library

* Update version of omh auth library
  • Loading branch information
HectorNarvaez committed May 18, 2023
1 parent ed4c933 commit fbdc1aa
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ subprojects {
mavenCentral()
google()
mavenLocal()
maven("https://s01.oss.sonatype.org/content/groups/staging/")
}
}

Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ object Libs {
val androidJunit by lazy { "androidx.test.ext:junit:${Versions.androidJunit}" }
val mockk by lazy { "io.mockk:mockk:${Versions.mockk}" }
val coroutineTesting by lazy { "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}" }

// Auth
val omhAuthLibrary by lazy { "com.openmobilehub.android:auth-api:${Versions.omhAuth}" }
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ object Versions {
const val junit = "4.13.2"
const val androidJunit = "1.1.5"
const val mockk = "1.13.4"

// Auth
const val omhAuth = "1.0.1"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.omh.android.storage.api.drive.nongms

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.storage.api.OmhStorageClient

internal class OmhStorageClientImpl(
context: Context
) : OmhStorageClient {
context: Context,
authClient: OmhAuthClient
) : OmhStorageClient(authClient) {

private val applicationContext: Context

Expand All @@ -14,12 +16,11 @@ internal class OmhStorageClientImpl(
}

internal class Builder : OmhStorageClient.Builder {
override fun build(context: Context): OmhStorageClient {
return OmhStorageClientImpl(context)
}
}

override fun setupAccessToken(token: String) {
// Implement THIS
override fun build(context: Context, authClient: OmhAuthClient) =
OmhStorageClientImpl(context, authClient)
}

// This will be implemented in a future PR
override fun getRepository() = Unit
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.omh.android.storage.api.drive.nongms

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.storage.api.OmhStorageClient
import com.omh.android.storage.api.OmhStorageFactory

class OmhStorageFactoryImpl : OmhStorageFactory {

override fun getStorageClient(
context: Context
) = OmhStorageClientImpl.Builder().build(context)
context: Context,
authClient: OmhAuthClient
): OmhStorageClient = OmhStorageClientImpl.Builder().build(context, authClient)
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.omh.android.storage.api.drive.nongms.data

import com.omh.android.auth.api.OmhCredentials
import com.omh.android.storage.api.drive.nongms.BuildConfig
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory

internal class GoogleRetrofitImpl(private val bearerToken: String) {
internal class GoogleRetrofitImpl(private val omhCredentials: OmhCredentials) {

companion object {
private const val HEADER_AUTHORIZATION_NAME = "Authorization"
private const val BEARER = "Bearer %s"

private var instance: GoogleRetrofitImpl? = null

internal fun getInstance(bearerToken: String): GoogleRetrofitImpl {
internal fun getInstance(omhCredentials: OmhCredentials): GoogleRetrofitImpl {
if (instance == null) {
instance = GoogleRetrofitImpl(bearerToken)
instance = GoogleRetrofitImpl(omhCredentials)
}

return instance!!
Expand Down Expand Up @@ -67,7 +69,7 @@ internal class GoogleRetrofitImpl(private val bearerToken: String) {
.newBuilder()
.addHeader(
HEADER_AUTHORIZATION_NAME,
bearerToken
BEARER.format(omhCredentials.accessToken.orEmpty())
)
.build()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.omh.android.storage.api.drive.nongms.data.source

import com.omh.android.auth.api.OmhCredentials
import com.omh.android.storage.api.data.source.remote.FileRemoteDataSource
import com.omh.android.storage.api.domain.model.File
import com.omh.android.storage.api.drive.nongms.data.GoogleRetrofitImpl
import com.omh.android.storage.api.drive.nongms.data.source.mapper.toFileList

internal class FileRemoteDataSource : FileRemoteDataSource {
internal class FileRemoteDataSource(private val authCredentials: OmhCredentials) : FileRemoteDataSource {

override fun getRootFilesList(): List<File> {
val response = GoogleRetrofitImpl
.getInstance("")
.getInstance(authCredentials)
.getGoogleStorageApiService()
.getRootFilesList()
.execute()
Expand Down
3 changes: 2 additions & 1 deletion storage-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ android {
dependencies {
implementation(Libs.reflection)
testImplementation(Libs.junit)
}
api(Libs.omhAuthLibrary)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.omh.android.storage.api

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient

interface OmhStorageClient {
abstract class OmhStorageClient protected constructor(protected val authClient: OmhAuthClient) {

interface Builder {
fun build(context: Context): OmhStorageClient

fun build(context: Context, authClient: OmhAuthClient): OmhStorageClient
}

fun setupAccessToken(token: String)
abstract fun getRepository()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.omh.android.storage.api

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient

interface OmhStorageFactory {
fun getStorageClient(context: Context): OmhStorageClient

fun getStorageClient(context: Context, authClient: OmhAuthClient): OmhStorageClient
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.omh.android.storage.api

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient
import kotlin.reflect.KClass

object OmhStorageProvider {

private const val NGMS_ADDRESS = "com.omh.android.storage.api.drive.nongms.OmhStorageFactoryImpl"

@SuppressWarnings("SwallowedException")
fun provideStorageClient(context: Context): OmhStorageClient {
fun provideStorageClient(context: Context, authClient: OmhAuthClient): OmhStorageClient {
val clazz: KClass<out Any> = Class.forName(NGMS_ADDRESS).kotlin
val omhStorageFactory = clazz.objectInstance as OmhStorageFactory
return omhStorageFactory.getStorageClient(context)
return omhStorageFactory.getStorageClient(context, authClient)
}
}

0 comments on commit fbdc1aa

Please sign in to comment.