-
Notifications
You must be signed in to change notification settings - Fork 199
/
AuthAWSCredentialsProvider.swift
50 lines (40 loc) · 1.42 KB
/
AuthAWSCredentialsProvider.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Amplify
import Foundation
public protocol AuthAWSCredentialsProvider {
/// Return the most recent Result of fetching the AWS Credentials
func getAWSCredentials() -> Result<AWSCredentials, AuthError>
}
public extension AuthAWSCredentialsProvider where Self: AWSAuthSessionBehavior {
/// Return the most recent Result of fetching the AWS Credentials. If the temporary credentials are expired, returns
/// a `AuthError.sessionExpired` failure.
func getAWSCredentials() -> Result<AWSCredentials, AuthError> {
let result: Result<AWSCredentials, AuthError>
switch awsCredentialsResult {
case .failure(let error): result = .failure(error)
case .success(let tempCreds):
if tempCreds.expiration > Date() {
result = .success(tempCreds)
} else {
result = .failure(AuthError.sessionExpired("AWS Credentials are expired", ""))
}
}
return result
}
}
public protocol AWSCredentialsProvider {
func fetchAWSCredentials() async throws -> AWSCredentials
}
public protocol AWSTemporaryCredentials: AWSCredentials {
var sessionToken: String { get }
var expiration: Date { get }
}
public protocol AWSCredentials {
var accessKeyId: String { get }
var secretAccessKey: String { get }
}