Token
public struct Token : Codable, Sendable
extension Token: CustomStringConvertible
Struct representing an OIDC token.
-
The access token used for authentication.
Declaration
Swift
public let accessToken: String
-
The type of token.
Declaration
Swift
public let tokenType: String?
-
The scope of access granted by the token.
Declaration
Swift
public let scope: String?
-
The duration of the token’s validity in seconds
Declaration
Swift
public let expiresIn: Int64
-
The refresh token used to obtain a new access token.
Declaration
Swift
public let refreshToken: String?
-
The ID token
Declaration
Swift
public let idToken: String?
-
The exact timestamp (in seconds since 1970) when the token expires.
Declaration
Swift
public let expiresAt: Int64
-
Initializes a new instance of
Token
.Declaration
Swift
public init(accessToken: String, tokenType: String?, scope: String?, expiresIn: Int64, refreshToken: String?, idToken: String?)
Parameters
accessToken
The access token string.
tokenType
The type of token.
scope
The scope of access granted by the token.
expiresIn
The duration (in seconds) for which the token is valid.
refreshToken
The refresh token string (optional).
idToken
The ID token string (optional).
-
A Boolean value indicating whether the token has expired.
Declaration
Swift
public var isExpired: Bool { get }
Return Value
true
if the current time is greater than or equal to the token’s expiry time; otherwise,false
. -
Checks if the token will expire within a specified threshold.
Declaration
Swift
public func isExpired(threshold: Int64) -> Bool
Parameters
threshold
The threshold duration (in seconds) to check for expiration.
Return Value
true
if the token will expire within the threshold; otherwise,false
. -
Decodes a
Token
instance from a decoder.Throws
An error if decoding fails.Declaration
Swift
public init(from decoder: Decoder) throws
Parameters
decoder
The decoder instance used for decoding.
-
Encodes the
Token
instance to an encoder.Throws
An error if encoding fails.Declaration
Swift
public func encode(to encoder: Encoder) throws
Parameters
encoder
The encoder instance used for encoding.
-
A textual representation of the
Token
instance.Declaration
Swift
public var description: String { get }