Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Created December 3, 2019 11:07
Show Gist options
  • Save albertodebortoli/318ad1e87826fb8a12d12303a547f988 to your computer and use it in GitHub Desktop.
Save albertodebortoli/318ad1e87826fb8a12d12303a547f988 to your computer and use it in GitHub Desktop.
used by 'Lessons learned from handling JWT on mobile' article on Medium
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