Created
December 3, 2019 11:07
-
-
Save albertodebortoli/318ad1e87826fb8a12d12303a547f988 to your computer and use it in GitHub Desktop.
used by 'Lessons learned from handling JWT on mobile' article on Medium
This file contains hidden or 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
typealias Token = String | |
typealias AuthorizationValue = String | |
struct UserAuthenticationInfo { | |
let bearerToken: Token // the JWT | |
let refreshToken: Token | |
let expiryDate: Date // computed on creation from 'exp' claim | |
var isValid: Bool { | |
return expiryDate.compare(Date()) == .orderedDescending | |
} | |
} | |
protocol TokenRefreshing { | |
func refreshAccessToken(_ refreshToken: Token, completion: @escaping (Result<UserAuthenticationInfo, Error>) -> Void) | |
} | |
protocol AuthenticationInfoStorage { | |
var userAuthenticationInfo: UserAuthenticationInfo? | |
func persistUserAuthenticationInfo(_ authenticationInfo: UserAuthenticationInfo?) | |
func wipeUserAuthenticationInfo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment