Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing leeway as present on the Android SDK #221

Open
4 tasks done
ppamorim opened this issue Mar 12, 2024 · 0 comments
Open
4 tasks done

Missing leeway as present on the Android SDK #221

ppamorim opened this issue Mar 12, 2024 · 0 comments
Labels
feature request A feature has been asked for or suggested by the community

Comments

@ppamorim
Copy link

Checklist

  • I have looked into the Readme and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Hi,

I noted that the Swift version of this library doesn't contain the leeway value as it's present on the auth0/JWTDecode.Android:

https://github.com/auth0/JWTDecode.Android/blob/ec4b54496e684c5fb9e65f5ebb36e6241ef46161/lib/src/main/java/com/auth0/android/jwt/JWT.java#L161-L171

The issue in this source code can be found here:

return date.compare(Date()) != ComparisonResult.orderedDescending

Is that right? Shouldn't the libraries behave the same between the platforms?

Regards

Describe the ideal solution

Transform the value expired into a function that allow a leeway time, example:

struct JWT {

    var expiresAt: Date?
    //...

    var expired: Bool {
        self.expired()
    }

    func expired(leeway: Int = 0) -> Bool {
        guard let date = self.expiresAt else {
            return false
        }
        return date.compare(applyLeeway(Date(), leeway)) != ComparisonResult.orderedDescending
    }

    private func applyLeeway(_ date: Date, _ leeway: Int) -> Date {
        return date //// + leeway
    }

}

Alternatives and current workarounds

While it's possible to modify the expiredAt, I don't believe it should be done as it's modifying the JWT content.

Additional context

No response

@ppamorim ppamorim added the feature request A feature has been asked for or suggested by the community label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

1 participant