Skip to content

Commit fc5b560

Browse files
authored
Add customClaims parameter to signIn after signUp/PasswordReset and GetAccessToken (#2566)
* Add claims request to parameters class * pass claims request to silent token retriever param * Send claims request json to token endpoint also for signIn after sspr and signUp * add new test for signIn after signUp * Add new test for signInAfterResetPassword * add new test for signIncontroller for signIn with continuation token. Check claims Request * check that claims request is assigned to silent token parameters object * fix lint warning * split comments in multiple lines
1 parent 5857ed0 commit fc5b560

19 files changed

+249
-16
lines changed

MSAL/MSAL.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@
301301
28A600A82C78BDD200455666 /* MFARequiredStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A600A72C78BDD200455666 /* MFARequiredStateTests.swift */; };
302302
28A600AA2C78E09F00455666 /* MSALNativeAuthMFAControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A600A92C78E09F00455666 /* MSALNativeAuthMFAControllerTests.swift */; };
303303
28ABE1762C5D213700F5275D /* MSALNativeAuthSignInIntrospectIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28ABE1752C5D213700F5275D /* MSALNativeAuthSignInIntrospectIntegrationTests.swift */; };
304+
28AF42FA2D96C15A009D1065 /* SignInAfterSignUpStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28AF42F92D96C14F009D1065 /* SignInAfterSignUpStateTests.swift */; };
305+
28AF42FB2D96C15A009D1065 /* SignInAfterSignUpStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28AF42F92D96C14F009D1065 /* SignInAfterSignUpStateTests.swift */; };
306+
28AF42FD2D96CBCF009D1065 /* SignInAfterResetPasswordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28AF42FC2D96CBC2009D1065 /* SignInAfterResetPasswordTests.swift */; };
307+
28AF42FE2D96CBCF009D1065 /* SignInAfterResetPasswordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28AF42FC2D96CBC2009D1065 /* SignInAfterResetPasswordTests.swift */; };
304308
28B28B832C6F46E50030D5C5 /* MFAStates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B28B822C6F46E50030D5C5 /* MFAStates.swift */; };
305309
28B28B8C2C6F4B570030D5C5 /* MFADelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B28B8B2C6F4B570030D5C5 /* MFADelegates.swift */; };
306310
28B28B922C6F611F0030D5C5 /* MSALAuthMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B28B912C6F611F0030D5C5 /* MSALAuthMethod.swift */; };
@@ -2061,6 +2065,8 @@
20612065
28A600A72C78BDD200455666 /* MFARequiredStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFARequiredStateTests.swift; sourceTree = "<group>"; };
20622066
28A600A92C78E09F00455666 /* MSALNativeAuthMFAControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSALNativeAuthMFAControllerTests.swift; sourceTree = "<group>"; };
20632067
28ABE1752C5D213700F5275D /* MSALNativeAuthSignInIntrospectIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSALNativeAuthSignInIntrospectIntegrationTests.swift; sourceTree = "<group>"; };
2068+
28AF42F92D96C14F009D1065 /* SignInAfterSignUpStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInAfterSignUpStateTests.swift; sourceTree = "<group>"; };
2069+
28AF42FC2D96CBC2009D1065 /* SignInAfterResetPasswordTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInAfterResetPasswordTests.swift; sourceTree = "<group>"; };
20642070
28B28B822C6F46E50030D5C5 /* MFAStates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFAStates.swift; sourceTree = "<group>"; };
20652071
28B28B8B2C6F4B570030D5C5 /* MFADelegates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFADelegates.swift; sourceTree = "<group>"; };
20662072
28B28B912C6F611F0030D5C5 /* MSALAuthMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSALAuthMethod.swift; sourceTree = "<group>"; };
@@ -4574,6 +4580,8 @@
45744580
E20C21822A7A6C7300E31598 /* sign_in */ = {
45754581
isa = PBXGroup;
45764582
children = (
4583+
28AF42FC2D96CBC2009D1065 /* SignInAfterResetPasswordTests.swift */,
4584+
28AF42F92D96C14F009D1065 /* SignInAfterSignUpStateTests.swift */,
45774585
E20C21832A7A6CA400E31598 /* SignInCodeRequiredStateTests.swift */,
45784586
E20C218A2A7A805800E31598 /* SignInPasswordRequiredStateTests.swift */,
45794587
);
@@ -7168,6 +7176,7 @@
71687176
DECC1FB329531032006D9FB1 /* MSALLogMaskTests.m in Sources */,
71697177
B2ADD76E22C08B6A0093FD43 /* MSALLegacySharedAccountTestUtil.m in Sources */,
71707178
58B81F7124AC5D7200E8799E /* MSALTestCacheTokenResponse.m in Sources */,
7179+
28AF42FA2D96C15A009D1065 /* SignInAfterSignUpStateTests.swift in Sources */,
71717180
DE0D659729C1DCCF005798B1 /* MSALNativeAuthTokenRequestParametersTest.swift in Sources */,
71727181
E25BC099299555C000588549 /* MSALNativeAuthTelemetryTestDispatcher.swift in Sources */,
71737182
E25BC0832995429D00588549 /* MSALNativeAuthCacheMocks.swift in Sources */,
@@ -7192,6 +7201,7 @@
71927201
E22427EC2B0662050006C55E /* SignUpPasswordRequiredDelegateDispatcherTests.swift in Sources */,
71937202
DE5738BC2A8F79A800D9120D /* MSALNativeAuthResetPasswordPollCompletionResponseErrorTests.swift in Sources */,
71947203
E22427FA2B0670600006C55E /* SignInVerifyCodeDelegateDispatcherTests.swift in Sources */,
7204+
28AF42FE2D96CBCF009D1065 /* SignInAfterResetPasswordTests.swift in Sources */,
71957205
E2EBD62A2A1BB7700049467A /* MSALNativeAuthSignUpResponseValidatorMock.swift in Sources */,
71967206
E25BC0852995430B00588549 /* MSALNativeAuthFactoriesMocks.swift in Sources */,
71977207
28A600962C78843C00455666 /* MFASendChallengeDelegateDispatcherTests.swift in Sources */,
@@ -7303,6 +7313,7 @@
73037313
A0274CBF24B432B100BD198D /* MSALAuthSchemeTests.m in Sources */,
73047314
DE8DC4F92C6621E700534E8F /* MSALNativeAuthResetPasswordControllerTests.swift in Sources */,
73057315
DE8DC5352C6621FD00534E8F /* SignUpCodeSentStateTests.swift in Sources */,
7316+
28AF42FD2D96CBCF009D1065 /* SignInAfterResetPasswordTests.swift in Sources */,
73067317
D69ADB401E516F9B00952049 /* MSALTestURLSessionDataTask.m in Sources */,
73077318
DE8DC5162C6621EF00534E8F /* SignInPasswordStartDelegateDispatcherTests.swift in Sources */,
73087319
6525115A29CD84A000D3B876 /* MSALPublicClientApplicationTests.m in Sources */,
@@ -7399,6 +7410,7 @@
73997410
2364C74C1FB3E5CC00835428 /* XCTestCase+HelperMethods.m in Sources */,
74007411
DE8DC54C2C66220D00534E8F /* MSALNativeAuthESTSApiErrorDescriptionsTests.swift in Sources */,
74017412
DE8DC4F72C6621E400534E8F /* MSALNativeAuthTestCase.swift in Sources */,
7413+
28AF42FB2D96C15A009D1065 /* SignInAfterSignUpStateTests.swift in Sources */,
74027414
DE8DC51A2C6621F100534E8F /* SignUpPasswordRequiredDelegateDispatcherTests.swift in Sources */,
74037415
DE8DC55B2C66221700534E8F /* MSALNativeAuthResetPasswordContinueRequestParametersTest.swift in Sources */,
74047416
DE8DC54D2C66220D00534E8F /* MSALNativeAuthSubErrorCodeTests.swift in Sources */,

MSAL/src/native_auth/controllers/sign_in/MSALNativeAuthSignInController.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
102102
username: String,
103103
continuationToken: String?,
104104
scopes: [String]?,
105+
claimsRequestJson: String?,
105106
telemetryId: MSALNativeAuthTelemetryApiId,
106107
context: MSALNativeAuthRequestContext
107108
) async -> SignInAfterPreviousFlowControllerResponse {
@@ -117,13 +118,12 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
117118
return .init(.failure(error), correlationId: context.correlationId())
118119
}
119120
let scopes = joinScopes(scopes)
120-
// currently, we don't support claimsRequest in signIn after signUp/SSPR
121121
guard let request = createTokenRequest(
122122
username: username,
123123
scopes: scopes,
124124
continuationToken: continuationToken,
125125
grantType: .continuationToken,
126-
claimsRequestJson: nil,
126+
claimsRequestJson: claimsRequestJson,
127127
context: context
128128
) else {
129129
let error = SignInAfterSignUpError(correlationId: context.correlationId())
@@ -133,12 +133,11 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
133133
let config = factory.makeMSIDConfiguration(scopes: scopes)
134134
let response = await performAndValidateTokenRequest(request, config: config, context: context)
135135

136-
// currently, we don't handle claimsRequest in signIn with continuation token
137136
return await withCheckedContinuation { continuation in
138137
handleTokenResponse(
139138
response,
140139
scopes: scopes,
141-
claimsRequestJson: nil,
140+
claimsRequestJson: claimsRequestJson,
142141
telemetryInfo: telemetryInfo,
143142
onSuccess: { accountResult in
144143
continuation.resume(
@@ -434,7 +433,13 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
434433
let event = makeAndStartTelemetryEvent(id: .telemetryApiIdMFAGetAuthMethods, context: context)
435434
let result = await performAndValidateIntrospectRequest(continuationToken: continuationToken, context: context)
436435
let telemetryInfo = TelemetryInfo(event: event, context: context)
437-
return handleIntrospectResponse(result, scopes: scopes, telemetryInfo: telemetryInfo, continuationToken: continuationToken, claimsRequestJson: claimsRequestJson)
436+
return handleIntrospectResponse(
437+
result,
438+
scopes: scopes,
439+
telemetryInfo: telemetryInfo,
440+
continuationToken: continuationToken,
441+
claimsRequestJson: claimsRequestJson
442+
)
438443
}
439444

440445
func submitChallenge(

MSAL/src/native_auth/controllers/sign_in/MSALNativeAuthSignInControlling.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protocol MSALNativeAuthSignInControlling {
3939
username: String,
4040
continuationToken: String?,
4141
scopes: [String]?,
42+
claimsRequestJson: String?,
4243
telemetryId: MSALNativeAuthTelemetryApiId,
4344
context: MSALNativeAuthRequestContext
4445
) async -> SignInAfterPreviousFlowControllerResponse

MSAL/src/native_auth/public/MSALNativeAuthUserAccountResult+Internal.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ extension MSALNativeAuthUserAccountResult {
2828

2929
func getAccessTokenInternal(forceRefresh: Bool,
3030
scopes: [String],
31+
claimsRequest: MSALClaimsRequest?,
3132
correlationId: UUID?,
3233
delegate: CredentialsDelegate) {
3334

3435
let params = MSALSilentTokenParameters(scopes: scopes, account: account)
3536
let context = MSALNativeAuthRequestContext(correlationId: correlationId)
3637
params.forceRefresh = forceRefresh
3738
params.correlationId = correlationId
39+
params.claimsRequest = claimsRequest
3840

3941
let challengeTypes = MSALNativeAuthPublicClientApplication.convertChallengeTypes(configuration.challengeTypes)
4042
let authority = try? MSALCIAMAuthority(url: configuration.authority.url)

MSAL/src/native_auth/public/MSALNativeAuthUserAccountResult.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ import Foundation
9090
format: "Retrieving access token with parameters started."
9191
)
9292

93-
getAccessTokenInternal(forceRefresh: parameters.forceRefresh ?? false,
93+
getAccessTokenInternal(forceRefresh: parameters.forceRefresh,
9494
scopes: parameters.scopes ?? [],
95+
claimsRequest: parameters.claimsRequest,
9596
correlationId: parameters.correlationId,
9697
delegate: delegate)
9798
}
@@ -112,6 +113,7 @@ import Foundation
112113

113114
getAccessTokenInternal(forceRefresh: forceRefresh,
114115
scopes: [],
116+
claimsRequest: nil,
115117
correlationId: correlationId,
116118
delegate: delegate)
117119
}
@@ -145,6 +147,7 @@ import Foundation
145147

146148
getAccessTokenInternal(forceRefresh: forceRefresh,
147149
scopes: scopes,
150+
claimsRequest: nil,
148151
correlationId: correlationId,
149152
delegate: delegate)
150153
}

MSAL/src/native_auth/public/parameters/MSALNativeAuthGetAccessTokenParameters.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class MSALNativeAuthGetAccessTokenParameters: NSObject {
3333
/// Not all scopes are guaranteed to be included in the access token returned.
3434
public var scopes: [String]?
3535

36+
/// The claims parameter that needs to be sent to the service.
37+
public var claimsRequest: MSALClaimsRequest?
38+
3639
/// UUID to correlate this request with the server for debugging.
3740
public var correlationId: UUID?
3841
}

MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInAfterResetPasswordParameters .swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ public class MSALNativeAuthSignInAfterResetPasswordParameters: NSObject {
2929
/// Permissions you want included in the access token received.
3030
/// Not all scopes are guaranteed to be included in the access token returned.
3131
public var scopes: [String]?
32+
33+
/// The claims parameter that needs to be sent to the service.
34+
public var claimsRequest: MSALClaimsRequest?
3235
}

MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInAfterSignUpParameters.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ public class MSALNativeAuthSignInAfterSignUpParameters: NSObject {
2929
/// Permissions you want included in the access token received.
3030
/// Not all scopes are guaranteed to be included in the access token returned.
3131
public var scopes: [String]?
32+
33+
/// The claims parameter that needs to be sent to the service.
34+
public var claimsRequest: MSALClaimsRequest?
3235
}

MSAL/src/native_auth/public/state_machine/delegate/ResetPasswordDelegates.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public protocol ResetPasswordVerifyCodeDelegate {
5656
@MainActor func onResetPasswordVerifyCodeError(error: VerifyCodeError, newState: ResetPasswordCodeRequiredState?)
5757

5858
/// Notifies the delegate that a password is required from the user to continue.
59-
/// - Note: If a flow requires this optional method and it is not implemented, then ``onResetPasswordVerifyCodeError(error:newState:)`` will be called.
59+
/// - Note: If a flow requires this optional method and it is not implemented,
60+
/// then ``onResetPasswordVerifyCodeError(error:newState:)`` will be called.
6061
/// - Parameter newState: An object representing the new state of the flow with follow on methods.
6162
@MainActor @objc optional func onPasswordRequired(newState: ResetPasswordRequiredState)
6263
}
@@ -71,7 +72,8 @@ public protocol ResetPasswordResendCodeDelegate {
7172
@MainActor func onResetPasswordResendCodeError(error: ResendCodeError, newState: ResetPasswordCodeRequiredState?)
7273

7374
/// Notifies the delegate that a verification code is required from the user to continue.
74-
/// - Note: If a flow requires this optional method and it is not implemented, then ``onResetPasswordResendCodeError(error:newState:)`` will be called.
75+
/// - Note: If a flow requires this optional method and it is not implemented,
76+
/// then ``onResetPasswordResendCodeError(error:newState:)`` will be called.
7577
/// - Parameters:
7678
/// - newState: An object representing the new state of the flow with follow on methods.
7779
/// - sentTo: The email/phone number that the code was sent to.
@@ -95,7 +97,8 @@ public protocol ResetPasswordRequiredDelegate {
9597
@MainActor func onResetPasswordRequiredError(error: PasswordRequiredError, newState: ResetPasswordRequiredState?)
9698

9799
/// Notifies the delegate that the reset password operation completed successfully.
98-
/// - Note: If a flow requires this optional method and it is not implemented, then ``onResetPasswordRequiredError(error:newState:)`` will be called.
100+
/// - Note: If a flow requires this optional method and it is not implemented,
101+
/// then ``onResetPasswordRequiredError(error:newState:)`` will be called.
99102
/// - Parameter newState: An object representing the new state of the flow with follow on methods.
100103
@MainActor @objc optional func onResetPasswordCompleted(newState: SignInAfterResetPasswordState)
101104
}

MSAL/src/native_auth/public/state_machine/state/SignInAfterPreviousFlowBaseState+Internal.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ extension SignInAfterPreviousFlowBaseState {
2828

2929
func signInInternal(
3030
scopes: [String]?,
31+
claimsRequestJson: String?,
3132
telemetryId: MSALNativeAuthTelemetryApiId
3233
) async -> MSALNativeAuthSignInControlling.SignInAfterPreviousFlowControllerResponse {
3334
let context = MSALNativeAuthRequestContext(correlationId: correlationId)
3435
return await controller.signIn(
3536
username: username,
3637
continuationToken: continuationToken,
3738
scopes: scopes,
39+
claimsRequestJson: claimsRequestJson,
3840
telemetryId: telemetryId,
3941
context: context
4042
)

0 commit comments

Comments
 (0)