From ae022e0f079c2313af4466a85c1e0edf4bfe142e Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 24 Jul 2022 13:44:42 +0200 Subject: [PATCH] Add refresh token api --- lib/src/main/java/com/tuti/api/TutiApiClient.java | 11 +++++++++++ .../com/tuti/api/authentication/SignInRequest.java | 13 +++++++++++++ .../main/java/com/tuti/api/data/TutiResponse.java | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.java b/lib/src/main/java/com/tuti/api/TutiApiClient.java index 6f18a36..a6047e4 100644 --- a/lib/src/main/java/com/tuti/api/TutiApiClient.java +++ b/lib/src/main/java/com/tuti/api/TutiApiClient.java @@ -94,6 +94,17 @@ public void SignIn(SignInRequest credentials, ResponseCallable o sendRequest(RequestMethods.POST, serverURL + Operations.SIGN_IN, credentials, SignInResponse.class, TutiResponse.class, onResponse, onError, null); } + /** + * RefreshToken used to refresh an existing token to keep user's session valid. + * @param credentials + * @param onResponse + * @param onError + */ + public void RefreshToken(SignInRequest credentials, ResponseCallable onResponse, ErrorCallable onError) { + sendRequest(RequestMethods.POST, serverURL + Operations.REFRESH_TOKEN, credentials, SignInResponse.class, TutiResponse.class, onResponse, onError, null); + } + + public void Signup(SignUpRequest signUpRequest, ResponseCallable onResponse, ErrorCallable onError) { sendRequest(RequestMethods.POST, serverURL + Operations.SIGN_UP, signUpRequest, SignUpResponse.class, TutiResponse.class, onResponse, onError, null); } diff --git a/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java b/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java index 4895e4e..1af2bce 100644 --- a/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java +++ b/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java @@ -1,9 +1,22 @@ package com.tuti.api.authentication; +import com.google.gson.annotations.SerializedName; + public class SignInRequest { private String username; private String password; + public String getOldToken() { + return oldToken; + } + + public void setOldToken(String oldToken) { + this.oldToken = oldToken; + } + + @SerializedName("authorization") + private String oldToken; + public String getUsername() { return username; } diff --git a/lib/src/main/java/com/tuti/api/data/TutiResponse.java b/lib/src/main/java/com/tuti/api/data/TutiResponse.java index 67062b9..6225ad6 100644 --- a/lib/src/main/java/com/tuti/api/data/TutiResponse.java +++ b/lib/src/main/java/com/tuti/api/data/TutiResponse.java @@ -11,6 +11,17 @@ public class TutiResponse { private String message; private String code; + public String getAuthorization() { + return authorization; + } + + public void setAuthorization(String authorization) { + this.authorization = authorization; + } + + private String authorization; + + public String getStatus() { return status; }