-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 added AuthorizationService(TODO: build logic for authenticate) + M…
…ainActivity changes
- Loading branch information
Showing
3 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
android/app/src/main/java/by/eapp/musicroom/data/AuthAuthenticator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package by.eapp.musicroom.data | ||
|
||
import by.eapp.musicroom.domain.model.RegistrationData | ||
import by.eapp.musicroom.domain.model.SubmitData | ||
import by.eapp.musicroom.domain.repo.login.AuthorizationService | ||
import by.eapp.musicroom.domain.repo.login.JwtTokenManager | ||
import by.eapp.musicroom.network.ApiService | ||
import okhttp3.Authenticator | ||
import javax.inject.Inject | ||
|
||
class AuthAuthenticator @Inject constructor( | ||
private val tokenManager: JwtTokenManager, | ||
private val apiService: ApiService, | ||
) : Authenticator, AuthorizationService { | ||
|
||
companion object { | ||
const val HEADER_AUTHORIZATION = "Authorization" | ||
const val TOKEN_TYPE = "Bearer" | ||
} | ||
|
||
|
||
// override fun authenticate(route: Route?, response: Response): Request? { | ||
// val currentToken = runBlocking { | ||
// tokenManager.getAccessJwt() | ||
// } | ||
// synchronized(this) { | ||
// val updatedToken = runBlocking { | ||
// tokenManager.getAccessJwt() | ||
// } | ||
// val token = if (currentToken != updatedToken) updatedToken else { | ||
// val newSessionResponse = runBlocking { apiService.refreshToken("") } | ||
// if (newSessionResponse.isSuccessful && newSessionResponse.body() != null) { | ||
// newSessionResponse.body()?.let { body -> | ||
// runBlocking { | ||
// tokenManager.saveAccessJwt(body.accessToken) | ||
// tokenManager.saveRefreshJwt(body.refreshToken) | ||
// } | ||
// body.accessToken | ||
// } | ||
// } else null | ||
// } | ||
// return if (token != null) response.request.newBuilder() | ||
// .header(HEADER_AUTHORIZATION, "$token") | ||
// .build() else null | ||
// } | ||
// } | ||
|
||
override suspend fun registerUser(registrationData: RegistrationData) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override suspend fun loginUser(login: String, password: String) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override suspend fun sendCode(userId: Int) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override suspend fun submitCode(submitData: SubmitData) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override suspend fun refreshToken(refreshToken: String) { | ||
TODO("Not yet implemented") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/by/eapp/musicroom/domain/repo/login/AuthorizationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package by.eapp.musicroom.domain.repo.login | ||
|
||
import by.eapp.musicroom.domain.model.RegistrationData | ||
import by.eapp.musicroom.domain.model.SubmitData | ||
|
||
interface AuthorizationService { | ||
suspend fun registerUser(registrationData: RegistrationData) | ||
suspend fun loginUser(login: String, password: String) | ||
suspend fun sendCode(userId: Int) | ||
suspend fun submitCode(submitData: SubmitData) | ||
suspend fun refreshToken(refreshToken: String) | ||
} |