Skip to content

Commit d97ff31

Browse files
spetrescu84nilo-ms
andauthored
Add parameters to public methods (#2492)
* add parametreized interface * Unit test for parameters * deprecated get access token * UserAccountResult tests * added tests for SignInAfter states * Objective C/SAmple app public * Update MSAL/src/native_auth/public/MSALNativeAuthPublicClientApplication.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthGetAccessTokenParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInAfterSignUpParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthSignUpParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthResetPasswordParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInAfterResetPasswordParameters .swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/parameters/MSALNativeAuthSignInParameters.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/MSALNativeAuthUserAccountResult.swift Co-authored-by: Danilo Raspa <[email protected]> * Update MSAL/src/native_auth/public/state_machine/state/SignInAfterResetPasswordState.swift Co-authored-by: Danilo Raspa <[email protected]> * PR Comments * PR Changes * Homogenized wording to flow * Add default value for force refresh * PR comments * Update changelog * Update changelog * Updated version * latest ic --------- Co-authored-by: Danilo Raspa <[email protected]>
1 parent fbe5509 commit d97ff31

24 files changed

+2110
-202
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [1.7.0]
2+
* Move native auth public methods to parameter class
3+
14
## [1.6.3]
25
* Merge 1.6.1-hotfix
36

MSAL/MSAL.xcodeproj/project.pbxproj

Lines changed: 50 additions & 6 deletions
Large diffs are not rendered by default.

MSAL/src/native_auth/controllers/sign_in/MSALNativeAuthSignInParameters.swift renamed to MSAL/src/native_auth/controllers/sign_in/MSALNativeAuthInternalSignInParameters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@_implementationOnly import MSAL_Private
2626

27-
class MSALNativeAuthSignInParameters {
27+
class MSALNativeAuthInternalSignInParameters {
2828
let username: String
2929
let password: String?
3030
let context: MSALNativeAuthRequestContext

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
7474

7575
// MARK: - Internal
7676

77-
func signIn(params: MSALNativeAuthSignInParameters) async -> SignInControllerResponse {
77+
func signIn(params: MSALNativeAuthInternalSignInParameters) async -> SignInControllerResponse {
7878
let eventId: MSALNativeAuthTelemetryApiId =
7979
params.password == nil ? .telemetryApiIdSignInWithCodeStart : .telemetryApiIdSignInWithPasswordStart
8080
MSALLogger.log(level: .info, context: params.context, format: "SignIn started")
@@ -737,7 +737,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
737737
// swiftlint:disable:next function_body_length
738738
private func handleChallengeResponse(
739739
_ validatedResponse: MSALNativeAuthSignInChallengeValidatedResponse,
740-
params: MSALNativeAuthSignInParameters,
740+
params: MSALNativeAuthInternalSignInParameters,
741741
telemetryInfo: TelemetryInfo
742742
) async -> SignInControllerResponse {
743743
let scopes = joinScopes(params.scopes)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protocol MSALNativeAuthSignInControlling {
3333
typealias SignInSubmitPasswordControllerResponse = MSALNativeAuthControllerTelemetryWrapper<SignInPasswordRequiredResult>
3434
typealias SignInResendCodeControllerResponse = MSALNativeAuthControllerTelemetryWrapper<SignInResendCodeResult>
3535

36-
func signIn(params: MSALNativeAuthSignInParameters) async -> SignInControllerResponse
36+
func signIn(params: MSALNativeAuthInternalSignInParameters) async -> SignInControllerResponse
3737

3838
func signIn(
3939
username: String,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension MSALNativeAuthPublicClientApplication {
7373

7474
let controller = controllerFactory.makeSignInController(cacheAccessor: cacheAccessor)
7575

76-
let params = MSALNativeAuthSignInParameters(
76+
let params = MSALNativeAuthInternalSignInParameters(
7777
username: username,
7878
password: password,
7979
context: context,

MSAL/src/native_auth/public/MSALNativeAuthPublicClientApplication.swift

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -149,26 +149,20 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
149149

150150
// MARK: delegate methods
151151

152-
/// Sign up a user with a given username and password.
152+
/// Sign up a user using parameters.
153153
/// - Parameters:
154-
/// - username: Username for the new account.
155-
/// - password: Optional. Password to be used for the new account.
156-
/// - attributes: Optional. User attributes to be used during account creation.
157-
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
154+
/// - parameters: Parameters used for the Sign Up flow.
158155
/// - delegate: Delegate that receives callbacks for the Sign Up flow.
159156
public func signUp(
160-
username: String,
161-
password: String? = nil,
162-
attributes: [String: Any]? = nil,
163-
correlationId: UUID? = nil,
157+
parameters: MSALNativeAuthSignUpParameters,
164158
delegate: SignUpStartDelegate
165159
) {
166160
Task {
167161
let controllerResponse = await signUpInternal(
168-
username: username,
169-
password: password,
170-
attributes: attributes,
171-
correlationId: correlationId
162+
username: parameters.username,
163+
password: parameters.password,
164+
attributes: parameters.attributes,
165+
correlationId: parameters.correlationId
172166
)
173167

174168
let delegateDispatcher = SignUpStartDelegateDispatcher(delegate: delegate, telemetryUpdate: controllerResponse.telemetryUpdate)
@@ -190,26 +184,47 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
190184
}
191185
}
192186

193-
/// Sign in a user with a given username and password.
187+
/// Sign up a user with a given username and password.
194188
/// - Parameters:
195-
/// - username: Username for the account
196-
/// - password: Optional. Password for the account.
197-
/// - scopes: Optional. Permissions you want included in the access token received after sign in flow has completed.
189+
/// - username: Username for the new account.
190+
/// - password: Optional. Password to be used for the new account.
191+
/// - attributes: Optional. User attributes to be used during account creation.
198192
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
199-
/// - delegate: Delegate that receives callbacks for the Sign In flow.
200-
public func signIn(
193+
/// - delegate: Delegate that receives callbacks for the Sign Up flow.
194+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'signUp(parameters:)' instead.")
195+
public func signUp(
201196
username: String,
202197
password: String? = nil,
203-
scopes: [String]? = nil,
198+
attributes: [String: Any]? = nil,
204199
correlationId: UUID? = nil,
200+
delegate: SignUpStartDelegate
201+
) {
202+
Task {
203+
let parameters = MSALNativeAuthSignUpParameters(username: username)
204+
parameters.password = password
205+
parameters.attributes = attributes
206+
parameters.correlationId = correlationId
207+
signUp(
208+
parameters: parameters,
209+
delegate: delegate
210+
)
211+
}
212+
}
213+
214+
/// Sign in a user using parameters.
215+
/// - Parameters:
216+
/// - parameters: Parameters used for the Sign In flow.
217+
/// - delegate: Delegate that receives callbacks for the Sign In flow.
218+
public func signIn(
219+
parameters: MSALNativeAuthSignInParameters,
205220
delegate: SignInStartDelegate
206221
) {
207222
Task {
208223
let controllerResponse = await signInInternal(
209-
username: username,
210-
password: password,
211-
scopes: scopes,
212-
correlationId: correlationId
224+
username: parameters.username,
225+
password: parameters.password,
226+
scopes: parameters.scopes,
227+
correlationId: parameters.correlationId
213228
)
214229

215230
let delegateDispatcher = SignInStartDelegateDispatcher(delegate: delegate, telemetryUpdate: controllerResponse.telemetryUpdate)
@@ -235,18 +250,42 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
235250
}
236251
}
237252

238-
/// Reset the password for a given username.
253+
/// Sign in a user with a given username and password.
239254
/// - Parameters:
240-
/// - username: Username for the account.
255+
/// - username: Username for the account
256+
/// - password: Optional. Password for the account.
257+
/// - scopes: Optional. Permissions you want included in the access token received after sign in flow has completed.
241258
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
242-
/// - delegate: Delegate that receives callbacks for the Reset Password flow.
243-
public func resetPassword(
259+
/// - delegate: Delegate that receives callbacks for the Sign In flow.
260+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'signIn(parameters:)' instead.")
261+
public func signIn(
244262
username: String,
263+
password: String? = nil,
264+
scopes: [String]? = nil,
245265
correlationId: UUID? = nil,
266+
delegate: SignInStartDelegate
267+
) {
268+
let parameters = MSALNativeAuthSignInParameters(username: username)
269+
parameters.password = password
270+
parameters.scopes = scopes
271+
parameters.correlationId = correlationId
272+
signIn(
273+
parameters: parameters,
274+
delegate: delegate
275+
)
276+
}
277+
278+
/// Reset the password using parameters
279+
/// - Parameters:
280+
/// - parameters: Parameters used for the Reset Password flow.
281+
/// - delegate: Delegate that receives callbacks for the Reset Password flow.
282+
public func resetPassword(
283+
parameters: MSALNativeAuthResetPasswordParameters,
246284
delegate: ResetPasswordStartDelegate
247285
) {
248286
Task {
249-
let controllerResponse = await resetPasswordInternal(username: username, correlationId: correlationId)
287+
let controllerResponse = await resetPasswordInternal(username: parameters.username,
288+
correlationId: parameters.correlationId)
250289

251290
let delegateDispatcher = ResetPasswordStartDelegateDispatcher(delegate: delegate, telemetryUpdate: controllerResponse.telemetryUpdate)
252291

@@ -265,6 +304,25 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
265304
}
266305
}
267306

307+
/// Reset the password for a given username.
308+
/// - Parameters:
309+
/// - username: Username for the account.
310+
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
311+
/// - delegate: Delegate that receives callbacks for the Reset Password flow.
312+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'resetPassword(parameters:)' instead.")
313+
public func resetPassword(
314+
username: String,
315+
correlationId: UUID? = nil,
316+
delegate: ResetPasswordStartDelegate
317+
) {
318+
let parameters = MSALNativeAuthResetPasswordParameters(username: username)
319+
parameters.correlationId = correlationId
320+
resetPassword(
321+
parameters: parameters,
322+
delegate: delegate
323+
)
324+
}
325+
268326
/// Retrieve the current signed in account from the cache.
269327
/// - Parameter correlationId: Optional. UUID to correlate this request with the server for debugging.
270328
/// - Returns: An object representing the account information if present in the local cache.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extension MSALNativeAuthUserAccountResult {
105105
let mfaRequiredErrorCode = 50076
106106
return errorCodes.contains(mfaRequiredErrorCode)
107107
}
108-
108+
109109
private func isResetPasswordRequiredError(errorCodes: [Int]) -> Bool {
110110
return errorCodes.contains(MSALNativeAuthESTSApiErrorCodes.resetPasswordRequired.rawValue)
111111
}

MSAL/src/native_auth/public/MSALNativeAuthUserAccountResult.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,32 @@ import Foundation
7676
}
7777
}
7878

79+
// Retrieves the access token for the currently signed in account from the cache for the provided parameters.
80+
/// - Parameters:
81+
/// - parameters: Parameters used for the Get Access Token flow.
82+
/// - delegate: Delegate that receives callbacks for the Get Access Token flow.
83+
///
84+
@objc public func getAccessToken(parameters: MSALNativeAuthGetAccessTokenParameters,
85+
delegate: CredentialsDelegate) {
86+
87+
MSALLogger.log(
88+
level: .info,
89+
context: nil,
90+
format: "Retrieving access token with parameters started."
91+
)
92+
93+
getAccessTokenInternal(forceRefresh: parameters.forceRefresh ?? false,
94+
scopes: parameters.scopes ?? [],
95+
correlationId: parameters.correlationId,
96+
delegate: delegate)
97+
}
98+
7999
/// Retrieves the access token for the default OIDC(openid, offline_access, profile) scopes from the cache.
80100
/// - Parameters:
81101
/// - forceRefresh: Optional. Ignore any existing access token in the cache and force MSAL to get a new access token from the service.
82102
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
83103
/// - delegate: Delegate that receives callbacks for the Get Access Token flow.
104+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'getAccessToken(parameters:)' instead.")
84105
@objc public func getAccessToken(forceRefresh: Bool = false,
85106
correlationId: UUID? = nil,
86107
delegate: CredentialsDelegate) {
@@ -104,6 +125,7 @@ import Foundation
104125
/// - forceRefresh: Optional. Ignore any existing access token in the cache and force MSAL to get a new access token from the service.
105126
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
106127
/// - delegate: Delegate that receives callbacks for the Get Access Token flow.
128+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'getAccessToken(parameters:)' instead.")
107129
public func getAccessToken(scopes: [String],
108130
forceRefresh: Bool = false,
109131
correlationId: UUID? = nil,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
/// Encapsulates the parameters passed to the getAccessToken method of MSALNativeAuthUserAccountResult
26+
@objcMembers
27+
public class MSALNativeAuthGetAccessTokenParameters: NSObject {
28+
29+
/// Set to true to ignore any existing access token in the cache and force MSAL to get a new access token from the service.
30+
public var forceRefresh: Bool = false
31+
32+
/// Permissions you want included in the access token received.
33+
/// Not all scopes are guaranteed to be included in the access token returned.
34+
public var scopes: [String]?
35+
36+
/// UUID to correlate this request with the server for debugging.
37+
public var correlationId: UUID?
38+
}

0 commit comments

Comments
 (0)