-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathAuthAWSCredentialsProvider.swift
More file actions
75 lines (60 loc) · 2.55 KB
/
Copy pathAuthAWSCredentialsProvider.swift
File metadata and controls
75 lines (60 loc) · 2.55 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// 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): .failure(error)
case .success(let tempCreds):
if tempCreds.expiration > Date() {
.success(tempCreds)
} else {
.failure(AuthError.sessionExpired("AWS Credentials are expired", ""))
}
}
return result
}
}
public protocol AWSCredentialsProvider {
func fetchAWSCredentials() async throws -> AWSCredentials
}
/**
Represents AWS credentials.
Typically refers to long-term credentials that do not expire unless manually rotated or deactivated.
These credentials are generally associated with an IAM (Identity and Access Management) user and are used to authenticate API requests to AWS services.
- Properties:
- accessKeyId: A unique identifier.
- secretAccessKey: A secret key used to sign requests cryptographically.
*/
public protocol AWSCredentials: Sendable {
/// A unique identifier.
var accessKeyId: String { get }
/// A secret key used to sign requests cryptographically.
var secretAccessKey: String { get }
}
/**
Represents temporary AWS credentials.
Refers to short-term credentials generated by AWS STS (Security Token Service).
These credentials are used for temporary access, often for applications, temporary roles, federated users, or scenarios requiring limited-time access.
- Inherits: AWSCredentials
- Properties:
- sessionToken: A token that is required when using temporary security credentials to sign requests.
- expiration: The expiration date and time of the temporary credentials.
*/
public protocol AWSTemporaryCredentials: AWSCredentials {
/// A token that is required when using temporary security credentials to sign requests.
var sessionToken: String { get }
/// The expiration date and time of the temporary credentials.
var expiration: Date { get }
}