Skip to content

Commit

Permalink
Use java.time.Instant instead of java.text.SimpleDateFormat (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon authored Oct 9, 2024
1 parent 77aa8b1 commit 66ad9ff
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.toMap
import com.auth0.auth0_flutter.utils.assertHasProperties
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.*

private const val AUTH_LOGIN_METHOD = "auth#login"
Expand Down Expand Up @@ -54,10 +53,7 @@ class LoginApiRequestHandler : ApiRequestHandler {

override fun onSuccess(credentials: Credentials) {
val scope = credentials.scope?.split(" ") ?: listOf()
val sdf =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)

val formattedDate = sdf.format(credentials.expiresAt)
val formattedDate = credentials.expiresAt.toInstant().toString()
result.success(
mapOf(
"accessToken" to credentials.accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.toMap
import com.auth0.auth0_flutter.utils.assertHasProperties
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.*

private const val AUTH_LOGIN_OTP_METHOD = "auth#loginOtp"
Expand Down Expand Up @@ -42,10 +41,7 @@ class LoginWithOtpApiRequestHandler: ApiRequestHandler {

override fun onSuccess(credentials: Credentials) {
val scope = credentials.scope?.split(" ") ?: listOf()
val sdf =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)

val formattedDate = sdf.format(credentials.expiresAt)
var formattedDate = credentials.expiresAt.toInstant().toString()
result.success(
mapOf(
"accessToken" to credentials.accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.toMap
import com.auth0.auth0_flutter.utils.assertHasProperties
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.Locale

private const val AUTH_RENEW_METHOD = "auth#renew"

Expand Down Expand Up @@ -46,10 +44,7 @@ class RenewApiRequestHandler : ApiRequestHandler {

override fun onSuccess(credentials: Credentials) {
val scope = credentials.scope?.split(" ") ?: listOf()
val sdf =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)

val formattedDate = sdf.format(credentials.expiresAt)
val formattedDate = credentials.expiresAt.toInstant().toString();

result.success(
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.auth0.android.result.Credentials
import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.toMap
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.*

class GetCredentialsRequestHandler : CredentialsManagerRequestHandler {
Expand Down Expand Up @@ -38,11 +37,7 @@ class GetCredentialsRequestHandler : CredentialsManagerRequestHandler {

override fun onSuccess(credentials: Credentials) {
val scopes = credentials.scope?.split(" ") ?: listOf()
val sdf =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)

val formattedDate = sdf.format(credentials.expiresAt)

val formattedDate = credentials.expiresAt.toInstant().toString()
result.success(
mapOf(
"accessToken" to credentials.accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import com.auth0.android.result.Credentials
import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.utils.assertHasProperties
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.Instant
import java.util.*


Expand All @@ -32,15 +31,14 @@ class SaveCredentialsRequestHandler : CredentialsManagerRequestHandler {
scope = scopes.joinToString(separator = " ")
}

val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)
val date = format.parse(credentials.get("expiresAt") as String)
val instant = Instant.parse(credentials.get("expiresAt") as String)

credentialsManager.saveCredentials(Credentials(
credentials.get("idToken") as String,
credentials.get("accessToken") as String,
credentials.get("tokenType") as String,
credentials.get("refreshToken") as String?,
date,
Date.from(instant),
scope,
))
result.success(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.auth0.android.result.Credentials
import com.auth0.auth0_flutter.request_handlers.MethodCallRequest
import com.auth0.auth0_flutter.toMap
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.*

class LoginWebAuthRequestHandler(private val builderResolver: (MethodCallRequest) -> WebAuthProvider.Builder) : WebAuthRequestHandler {
Expand Down Expand Up @@ -69,10 +68,7 @@ class LoginWebAuthRequestHandler(private val builderResolver: (MethodCallRequest
override fun onSuccess(credentials: Credentials) {
// Success! Access token and ID token are presents
val scopes = credentials.scope?.split(" ") ?: listOf()
val sdf =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)

val formattedDate = sdf.format(credentials.expiresAt)
val formattedDate = credentials.expiresAt.toInstant().toString()

result.success(
mapOf(
Expand Down

0 comments on commit 66ad9ff

Please sign in to comment.