Skip to content

Commit

Permalink
feat: added origin header in authorize session API.
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
grvgoel81 authored and Gaurav Goel committed Sep 4, 2024
1 parent f4a0c71 commit a1d76ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SessionManagerTest {
).get()
sessionManager = SessionManager(context)
val authResponse = sessionManager.authorizeSession(
"",
context
).get()
val resp = JSONObject(authResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SessionManager(context: Context) {
* Authorize User session in order to avoid re-login
*/

fun authorizeSession(context: Context): CompletableFuture<String> {
fun authorizeSession(origin: String, context: Context): CompletableFuture<String> {
return CompletableFuture.supplyAsync {
if (!ApiHelper.isNetworkAvailable(context)) {
throw Exception(
Expand All @@ -84,13 +84,14 @@ class SessionManager(context: Context) {
runBlocking {
withContext(Dispatchers.IO) {
web3AuthApi.authorizeSession(
origin = origin,
AuthorizeSessionRequest(key = pubKey)
)
}
}


if (!(response.isSuccessful && response.body() != null && response.body()?.message != null)) {
if (!(response.isSuccessful && response.body() != null && response.body()?.message != "")) {
throw Exception(
SessionManagerError.getError(
ErrorCode.NOUSERFOUND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.web3auth.session_manager_android.models.StoreApiResponse
import org.json.JSONObject
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface Web3AuthApi {
Expand All @@ -14,7 +15,10 @@ interface Web3AuthApi {
suspend fun createSession(@Body sessionRequestBody: SessionRequestBody): Response<JSONObject>

@POST("/v2/store/get")
suspend fun authorizeSession(@Body authorizeSessionRequest: AuthorizeSessionRequest): Response<StoreApiResponse>
suspend fun authorizeSession(
@Header("origin") origin: String,
@Body authorizeSessionRequest: AuthorizeSessionRequest
): Response<StoreApiResponse>

@POST("/v2/store/set")
suspend fun invalidateSession(@Body sessionRequestBody: SessionRequestBody): Response<JSONObject>
Expand Down

0 comments on commit a1d76ae

Please sign in to comment.