Skip to content

Commit 408044b

Browse files
authored
chore: kickoff release
2 parents 2fe2727 + 99a521c commit 408044b

File tree

22 files changed

+641
-39
lines changed

22 files changed

+641
-39
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ASF/CognitoUserPoolASF.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct CognitoUserPoolASF: AdvancedSecurityBehavior {
8686
contextData: [String: String],
8787
userPoolId: String
8888
) throws -> String {
89-
let timestamp = String(format: "%lli", floor(Date().timeIntervalSince1970 * 1_000))
89+
let timestamp = String(format: "%lli", Int64(Date().timeIntervalSince1970 * 1_000))
9090
let payload = [
9191
"contextData": contextData,
9292
"username": username,

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,12 @@ struct MigrateLegacyCredentialStore: Action {
316316
scopes: scopes ?? [],
317317
providerInfo: provider,
318318
presentationAnchor: nil,
319-
preferPrivateSession: false
319+
preferPrivateSession: false,
320+
nonce: nil,
321+
language: nil,
322+
loginHint: nil,
323+
prompt: nil,
324+
resource: nil
320325
))
321326
default:
322327
return .apiBased(.userSRP)

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct InformSessionError: Action {
2121
logVerbose("\(#fileID) Starting execution", environment: environment)
2222
let event: AuthorizationEvent = switch error {
2323
case .service(let serviceError):
24-
if isNotAuthorizedError(serviceError) {
24+
if serviceError is AWSCognitoIdentityProvider.NotAuthorizedException {
2525
.init(eventType: .throwError(
2626
.sessionExpired(error: serviceError)))
2727
} else {
@@ -34,11 +34,6 @@ struct InformSessionError: Action {
3434
logVerbose("\(#fileID) Sending event \(event.type)", environment: environment)
3535
await dispatcher.send(event)
3636
}
37-
38-
func isNotAuthorizedError(_ error: Error) -> Bool {
39-
error is AWSCognitoIdentity.NotAuthorizedException
40-
|| error is AWSCognitoIdentityProvider.NotAuthorizedException
41-
}
4237
}
4338

4439
extension InformSessionError: DefaultLogger {

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignUp/ConfirmSignUp.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ struct ConfirmSignUp: Action {
4949
await dispatcher.send(SignUpEvent(eventType: .signedUp(dataToSend, .init(.done))))
5050
}
5151
} catch let error as SignUpError {
52-
let errorEvent = SignUpEvent(eventType: .throwAuthError(error))
52+
let errorEvent = SignUpEvent(eventType: .throwAuthError(error, data))
5353
logVerbose(
5454
"\(#fileID) Sending event \(errorEvent)",
5555
environment: environment
5656
)
5757
await dispatcher.send(errorEvent)
5858
} catch {
5959
let error = SignUpError.service(error: error)
60-
let errorEvent = SignUpEvent(eventType: .throwAuthError(error))
60+
let errorEvent = SignUpEvent(eventType: .throwAuthError(error, data))
6161
logVerbose(
6262
"\(#fileID) Sending event \(errorEvent)",
6363
environment: environment

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignUp/InitiateSignUp.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ struct InitiateSignUp: Action {
6363
}
6464
await dispatcher.send(event)
6565
} catch let error as SignUpError {
66-
let errorEvent = SignUpEvent(eventType: .throwAuthError(error))
66+
let errorEvent = SignUpEvent(eventType: .throwAuthError(error, data))
6767
logVerbose(
6868
"\(#fileID) Sending event \(errorEvent)",
6969
environment: environment
7070
)
7171
await dispatcher.send(errorEvent)
7272
} catch {
7373
let error = SignUpError.service(error: error)
74-
let errorEvent = SignUpEvent(eventType: .throwAuthError(error))
74+
let errorEvent = SignUpEvent(eventType: .throwAuthError(error, data))
7575
logVerbose(
7676
"\(#fileID) Sending event \(errorEvent)",
7777
environment: environment

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Options/AWSAuthWebUISignInOptions.swift

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,76 @@ public struct AWSAuthWebUISignInOptions {
2727
/// Safari always honors the request.
2828
public let preferPrivateSession: Bool
2929

30+
/// A random value that you can add to the request. The nonce value that you provide is included in the ID token
31+
/// that Amazon Cognito issues. To guard against replay attacks, your app can inspect the nonce claim in the ID
32+
/// token and compare it to the one you generated.
33+
public let nonce: String?
34+
35+
/// The language that you want to display user-interactive pages in
36+
/// For more information, see Managed login localization -
37+
/// https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-managed-login.html#managed-login-localization
38+
public let language: String?
39+
40+
/// A username prompt that you want to pass to the authorization server. You can collect a username, email
41+
/// address or phone number from your user and allow the destination provider to pre-populate the user's
42+
/// sign-in name.
43+
public let loginHint: String?
44+
45+
/// An OIDC parameter that controls authentication behavior for existing sessions.
46+
public let prompt: [Prompt]?
47+
48+
/// The identifier of a resource that you want to bind to the access token in the `aud` claim. When you include
49+
/// this parameter, Amazon Cognito validates that the value is a URL and sets the audience of the resulting
50+
/// access token to the requested resource. Values for this parameter must begin with "https://", "http://localhost",
51+
/// or a custom URL scheme like "myapp://".
52+
public let resource: String?
53+
3054
public init(
3155
idpIdentifier: String? = nil,
32-
preferPrivateSession: Bool = false
56+
preferPrivateSession: Bool = false,
57+
nonce: String? = nil,
58+
language: String? = nil,
59+
loginHint: String? = nil,
60+
prompt: [Prompt]? = nil,
61+
resource: String? = nil
3362
) {
3463
self.idpIdentifier = idpIdentifier
3564
self.preferPrivateSession = preferPrivateSession
65+
self.nonce = nonce
66+
self.language = language
67+
self.loginHint = loginHint
68+
self.prompt = prompt
69+
self.resource = resource
70+
}
71+
}
72+
73+
public extension AWSAuthWebUISignInOptions {
74+
75+
enum Prompt: String, Codable {
76+
/// Amazon Cognito silently continues authentication for users who have a valid authenticated session.
77+
/// With this prompt, users can silently authenticate between different app clients in your user pool.
78+
/// If the user is not already authenticated, the authorization server returns a login_required error.
79+
case none
80+
81+
/// Amazon Cognito requires users to re-authenticate even if they have an existing session. Send this
82+
/// value when you want to verify the user's identity again. Authenticated users who have an existing
83+
/// session can return to sign-in without invalidating that session. When a user who has an existing
84+
/// session signs in again, Amazon Cognito assigns them a new session cookie. This parameter can also
85+
/// be forwarded to your IdPs. IdPs that accept this parameter also request a new authentication
86+
/// attempt from the user.
87+
case login
88+
89+
/// This value has no effect on local sign-in and must be submitted in requests that redirect to IdPs.
90+
/// When included in your authorization request, this parameter adds prompt=select_account to the URL
91+
/// path for the IdP redirect destination. When IdPs support this parameter, they request that users
92+
/// select the account that they want to log in with.
93+
case selectAccount = "select_account"
94+
95+
/// This value has no effect on local sign-in and must be submitted in requests that redirect to IdPs.
96+
/// When included in your authorization request, this parameter adds prompt=consent to the URL path for
97+
/// the IdP redirect destination. When IdPs support this parameter, they request user consent before
98+
/// they redirect back to your user pool.
99+
case consent
36100
}
37101
}
38102

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ struct HostedUISignInHelper: DefaultLogger {
131131
scopes: request.options.scopes ?? scopeFromConfig,
132132
providerInfo: providerInfo,
133133
presentationAnchor: request.presentationAnchor,
134-
preferPrivateSession: privateSession
134+
preferPrivateSession: privateSession,
135+
nonce: pluginOptions?.nonce,
136+
language: pluginOptions?.language,
137+
loginHint: pluginOptions?.loginHint,
138+
promptValues: pluginOptions?.prompt,
139+
resource: pluginOptions?.resource
135140
)
136141
let signInData = SignInEventData(
137142
username: nil,

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIOptions.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ struct HostedUIOptions {
1717
let presentationAnchor: AuthUIPresentationAnchor?
1818

1919
let preferPrivateSession: Bool
20+
21+
let nonce: String?
22+
23+
let language: String?
24+
25+
let loginHint: String?
26+
27+
let prompt: String?
28+
29+
let resource: String?
2030
}
2131

2232
extension HostedUIOptions: Codable {
@@ -28,6 +38,16 @@ extension HostedUIOptions: Codable {
2838
case providerInfo
2939

3040
case preferPrivateSession
41+
42+
case nonce
43+
44+
case language = "lang"
45+
46+
case loginHint = "login_hint"
47+
48+
case prompt
49+
50+
case resource
3151
}
3252

3353
init(from decoder: Decoder) throws {
@@ -36,14 +56,52 @@ extension HostedUIOptions: Codable {
3656
self.providerInfo = try values.decode(HostedUIProviderInfo.self, forKey: .providerInfo)
3757
self.preferPrivateSession = try values.decode(Bool.self, forKey: .preferPrivateSession)
3858
self.presentationAnchor = nil
59+
self.nonce = try values.decode(String.self, forKey: .nonce)
60+
self.language = try values.decode(String.self, forKey: .language)
61+
self.loginHint = try values.decode(String.self, forKey: .loginHint)
62+
self.prompt = try values.decode(String.self, forKey: .prompt)
63+
self.resource = try values.decode(String.self, forKey: .resource)
3964
}
4065

4166
func encode(to encoder: Encoder) throws {
4267
var container = encoder.container(keyedBy: CodingKeys.self)
4368
try container.encode(scopes, forKey: .scopes)
4469
try container.encode(providerInfo, forKey: .providerInfo)
4570
try container.encode(preferPrivateSession, forKey: .preferPrivateSession)
71+
try container.encode(nonce, forKey: .nonce)
72+
try container.encode(language, forKey: .language)
73+
try container.encode(loginHint, forKey: .loginHint)
74+
try container.encodeIfPresent(prompt, forKey: .prompt)
75+
try container.encode(resource, forKey: .resource)
4676
}
4777
}
4878

4979
extension HostedUIOptions: Equatable { }
80+
81+
#if os(iOS) || os(macOS) || os(visionOS)
82+
extension HostedUIOptions {
83+
init(
84+
scopes: [String],
85+
providerInfo: HostedUIProviderInfo,
86+
presentationAnchor: AuthUIPresentationAnchor?,
87+
preferPrivateSession: Bool,
88+
nonce: String?,
89+
language: String?,
90+
loginHint: String?,
91+
promptValues: [AWSAuthWebUISignInOptions.Prompt]?,
92+
resource: String?
93+
) {
94+
self.init(
95+
scopes: scopes,
96+
providerInfo: providerInfo,
97+
presentationAnchor: presentationAnchor,
98+
preferPrivateSession: preferPrivateSession,
99+
nonce: nonce,
100+
language: language,
101+
loginHint: loginHint,
102+
prompt: promptValues?.map { "\($0.rawValue)" }.joined(separator: " "),
103+
resource: resource
104+
)
105+
}
106+
}
107+
#endif

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SignUpEvent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct SignUpEvent: StateMachineEvent {
2121
case initiateSignUpComplete(SignUpEventData, AuthSignUpResult)
2222
case confirmSignUp(SignUpEventData, ConfirmationCode, ForceAliasCreation?)
2323
case signedUp(SignUpEventData, AuthSignUpResult)
24-
case throwAuthError(SignUpError)
24+
case throwAuthError(SignUpError, SignUpEventData)
2525
}
2626

2727
init(

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/SignUpState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum SignUpState: State {
1414
case awaitingUserConfirmation(SignUpEventData, AuthSignUpResult)
1515
case confirmingSignUp(SignUpEventData)
1616
case signedUp(SignUpEventData, AuthSignUpResult)
17-
case error(SignUpError)
17+
case error(SignUpError, SignUpEventData)
1818
}
1919

2020
extension SignUpState {

0 commit comments

Comments
 (0)