Customer application makes a network request to the Customer API to initiate the creation
of an access token for the ReadyRemit SDK
Customer API makes a network request to the ReadyRemit API to create an access token for
the ReadyRemit SDK
ReadyRemit API returns the access token details or an error
Customer API returns the access token details or an error
Customer application returns the access token details or throws an error
Return Type
public protocol AccessTokenDetails: Sendable {
var accessToken: String { get }
var expiresIn: Int { get }
var scope: String { get }
var tokenType: String { get }
}
Sample Implementation
private func fetchAccessTokenDetails() async throws -> AccessTokenDetails {
guard let url = URL(string: "https://example.com/v1/oauth/token") else {
throw URLError(.badURL)
}
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
let (data, urlResponse) = try await URLSession.shared.data(for: urlRequest)
guard let httpURLResponse = urlResponse as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
switch httpURLResponse.statusCode {
case 200...299:
// CreateAccessTokenDetailsResponse must conform to AccessTokenDetails
return try JSONDecoder().decode(CreateAccessTokenDetailsResponse.self, from: data)
default:
throw CustomError.unsuccessfulResponse
}
}