Skip to content

Commit 6389422

Browse files
Revert "Native Auth remove legacy interface" (#2586)
Co-authored-by: Swasti Gupta <[email protected]>
1 parent 4665b35 commit 6389422

12 files changed

+237
-222
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
## [1.9.0]
22
* Add feature flags provider to be controlled from broker (#2540)
33
* Added GitHub issue templates for better issue tracking and reporting (#2554)
4-
* Removed deprecated methods from native auth public interface (#2582)
54

65
## [1.8.1]
76
* Cherry pick DUNA "resume" action fix #2558

MSAL/src/native_auth/public/MSALNativeAuthPublicClientApplication.swift

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
184184
}
185185
}
186186

187+
/// Sign up a user with a given username and password.
188+
/// - Parameters:
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.
192+
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
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(
196+
username: String,
197+
password: String? = nil,
198+
attributes: [String: Any]? = nil,
199+
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+
187214
/// Sign in a user using parameters.
188215
/// - Parameters:
189216
/// - parameters: Parameters used for the Sign In flow.
@@ -225,6 +252,31 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
225252
}
226253
}
227254

255+
/// Sign in a user with a given username and password.
256+
/// - Parameters:
257+
/// - username: Username for the account
258+
/// - password: Optional. Password for the account.
259+
/// - scopes: Optional. Permissions you want included in the access token received after sign in flow has completed.
260+
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
261+
/// - delegate: Delegate that receives callbacks for the Sign In flow.
262+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'signIn(parameters:)' instead.")
263+
public func signIn(
264+
username: String,
265+
password: String? = nil,
266+
scopes: [String]? = nil,
267+
correlationId: UUID? = nil,
268+
delegate: SignInStartDelegate
269+
) {
270+
let parameters = MSALNativeAuthSignInParameters(username: username)
271+
parameters.password = password
272+
parameters.scopes = scopes
273+
parameters.correlationId = correlationId
274+
signIn(
275+
parameters: parameters,
276+
delegate: delegate
277+
)
278+
}
279+
228280
/// Reset the password using parameters
229281
/// - Parameters:
230282
/// - parameters: Parameters used for the Reset Password flow.
@@ -254,6 +306,25 @@ public final class MSALNativeAuthPublicClientApplication: MSALPublicClientApplic
254306
}
255307
}
256308

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

MSAL/src/native_auth/public/MSALNativeAuthUserAccountResult.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,59 @@ import Foundation
9696
correlationId: parameters.correlationId,
9797
delegate: delegate)
9898
}
99+
100+
/// Retrieves the access token for the default OIDC(openid, offline_access, profile) scopes from the cache.
101+
/// - Parameters:
102+
/// - forceRefresh: Optional. Ignore any existing access token in the cache and force MSAL to get a new access token from the service.
103+
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
104+
/// - delegate: Delegate that receives callbacks for the Get Access Token flow.
105+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'getAccessToken(parameters:)' instead.")
106+
@objc public func getAccessToken(forceRefresh: Bool = false,
107+
correlationId: UUID? = nil,
108+
delegate: CredentialsDelegate) {
109+
MSALNativeAuthLogger.log(
110+
level: .info,
111+
context: nil,
112+
format: "Retrieving access token without scopes.")
113+
114+
getAccessTokenInternal(forceRefresh: forceRefresh,
115+
scopes: [],
116+
claimsRequest: nil,
117+
correlationId: correlationId,
118+
delegate: delegate)
119+
}
120+
121+
/// Retrieves the access token for the currently signed in account from the cache such that
122+
/// the scope of retrieved access token is a superset of requested scopes. If the access token
123+
/// has expired, it will be refreshed using the refresh token that's stored in the cache. If no
124+
/// access token matching the requested scopes is found in cache then a new access token is fetched.
125+
/// - Parameters:
126+
/// - scopes: Permissions you want included in the access token received in the result. Not all scopes are guaranteed to be included in the access token returned.
127+
/// - forceRefresh: Optional. Ignore any existing access token in the cache and force MSAL to get a new access token from the service.
128+
/// - correlationId: Optional. UUID to correlate this request with the server for debugging.
129+
/// - delegate: Delegate that receives callbacks for the Get Access Token flow.
130+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'getAccessToken(parameters:)' instead.")
131+
public func getAccessToken(scopes: [String],
132+
forceRefresh: Bool = false,
133+
correlationId: UUID? = nil,
134+
delegate: CredentialsDelegate) {
135+
136+
guard inputValidator.isInputValid(scopes) else {
137+
Task { await delegate.onAccessTokenRetrieveError(error: RetrieveAccessTokenError(type: .invalidScope,
138+
correlationId: correlationId ?? UUID())) }
139+
return
140+
}
141+
142+
MSALNativeAuthLogger.log(
143+
level: .info,
144+
context: nil,
145+
format: "Retrieving access token with scopes started."
146+
)
147+
148+
getAccessTokenInternal(forceRefresh: forceRefresh,
149+
scopes: scopes,
150+
claimsRequest: nil,
151+
correlationId: correlationId,
152+
delegate: delegate)
153+
}
99154
}

MSAL/src/native_auth/public/state_machine/state/SignInAfterResetPasswordState.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,18 @@ import Foundation
5656
}
5757
}
5858
}
59+
60+
/// Sign in the user that just reset the password.
61+
/// - Parameters:
62+
/// - scopes: Optional. Permissions you want included in the access token received after sign in flow has completed.
63+
/// - delegate: Delegate that receives callbacks for the Sign In flow.
64+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'signIn(parameters:)' instead.")
65+
public func signIn(scopes: [String]? = nil, delegate: SignInAfterResetPasswordDelegate) {
66+
let parameters = MSALNativeAuthSignInAfterResetPasswordParameters()
67+
parameters.scopes = scopes
68+
signIn(
69+
parameters: parameters,
70+
delegate: delegate
71+
)
72+
}
5973
}

MSAL/src/native_auth/public/state_machine/state/SignInAfterSignUpState.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ import Foundation
5151
}
5252
}
5353
}
54+
55+
/// Sign in the user that signed up.
56+
/// - Parameters:
57+
/// - scopes: Optional. Permissions you want included in the access token received after sign in flow has completed.
58+
/// - delegate: Delegate that receives callbacks for the Sign In flow.
59+
@available(*, deprecated, message: "This method is now deprecated. Use the method 'signIn(parameters:)' instead.")
60+
public func signIn(scopes: [String]? = nil, delegate: SignInAfterSignUpDelegate) {
61+
let parameters = MSALNativeAuthSignInAfterSignUpParameters()
62+
parameters.scopes = scopes
63+
signIn(
64+
parameters: parameters,
65+
delegate: delegate)
66+
}
5467
}

MSAL/test/integration/native_auth/end_to_end/credentials/MSALNativeAuthUserAccountEndToEndTests.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ final class MSALNativeAuthUserAccountEndToEndTests: MSALNativeAuthEndToEndPasswo
119119
let signInExpectation = expectation(description: "signing in")
120120
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
121121

122-
let params = MSALNativeAuthSignInParameters(username: username)
123-
params.password = password
124-
params.scopes = ["User.Read"]
125-
params.correlationId = correlationId
126-
sut.signIn(parameters: params, delegate: signInDelegateSpy)
122+
sut.signIn(username: username, password: password, scopes: ["User.Read"], correlationId: correlationId, delegate: signInDelegateSpy)
127123

128124
await fulfillment(of: [signInExpectation])
129125

@@ -134,9 +130,7 @@ final class MSALNativeAuthUserAccountEndToEndTests: MSALNativeAuthEndToEndPasswo
134130
let getAccessTokenExpectation = expectation(description: "getting access token")
135131
let credentialsDelegateSpy = CredentialsDelegateSpy(expectation: getAccessTokenExpectation)
136132

137-
let getTokenParam = MSALNativeAuthGetAccessTokenParameters()
138-
getTokenParam.scopes = ["User.Read"]
139-
signInDelegateSpy.result?.getAccessToken(parameters: getTokenParam, delegate: credentialsDelegateSpy)
133+
signInDelegateSpy.result?.getAccessToken(scopes: ["User.Read"], delegate: credentialsDelegateSpy)
140134

141135
await fulfillment(of: [getAccessTokenExpectation])
142136

MSAL/test/integration/native_auth/end_to_end/reset_password/MSALNativeAuthResetPasswordEndToEndTests.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
8686
let codeRequiredExp = expectation(description: "code required")
8787
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: codeRequiredExp)
8888

89-
let param = MSALNativeAuthResetPasswordParameters(username: username)
90-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
89+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
9190

9291
await fulfillment(of: [codeRequiredExp])
9392
XCTAssertTrue(resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled)
@@ -131,8 +130,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
131130
let codeRequiredExp = expectation(description: "code required")
132131
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: codeRequiredExp)
133132

134-
let param = MSALNativeAuthResetPasswordParameters(username: username)
135-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
133+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
136134

137135
await fulfillment(of: [codeRequiredExp])
138136
XCTAssertTrue(resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled)
@@ -198,8 +196,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
198196

199197
let unknownUsername = UUID().uuidString + "@contoso.com"
200198

201-
let param = MSALNativeAuthResetPasswordParameters(username: unknownUsername)
202-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
199+
sut.resetPassword(username: unknownUsername, delegate: resetPasswordStartDelegate)
203200

204201
await fulfillment(of: [resetPasswordFailureExp])
205202

@@ -220,8 +217,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
220217
let resetPasswordFailureExp = expectation(description: "reset password web-fallback")
221218
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: resetPasswordFailureExp)
222219

223-
let param = MSALNativeAuthResetPasswordParameters(username: username)
224-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
220+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
225221

226222
await fulfillment(of: [resetPasswordFailureExp])
227223

@@ -242,8 +238,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
242238
let resetPasswordFailureExp = expectation(description: "does not support password")
243239
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: resetPasswordFailureExp)
244240

245-
let param = MSALNativeAuthResetPasswordParameters(username: username)
246-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
241+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
247242

248243
await fulfillment(of: [resetPasswordFailureExp])
249244

@@ -266,8 +261,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
266261
let resetPasswordFailureExp = expectation(description: "reset password user not found")
267262
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: resetPasswordFailureExp)
268263

269-
let param = MSALNativeAuthResetPasswordParameters(username: username)
270-
sut.resetPassword(parameters: param, delegate: resetPasswordStartDelegate)
264+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
271265

272266
await fulfillment(of: [resetPasswordFailureExp])
273267

MSAL/test/integration/native_auth/end_to_end/sign_in/MSALNativeAuthSignInUserNameAndPasswordEndToEndTests.swift

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
4040
let signInExpectation = expectation(description: "signing in")
4141
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
4242

43-
let parameters = MSALNativeAuthSignInParameters(username: username)
44-
parameters.password = password
45-
parameters.correlationId = correlationId
46-
sut.signIn(parameters: parameters, delegate: signInDelegateSpy)
43+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
4744

4845
await fulfillment(of: [signInExpectation])
4946

@@ -84,11 +81,8 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
8481

8582
let signInExpectation = expectation(description: "signing in")
8683
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
87-
88-
let signInParam = MSALNativeAuthSignInParameters(username: username)
89-
signInParam.password = "An Invalid Password"
90-
signInParam.correlationId = correlationId
91-
sut.signIn(parameters: signInParam, delegate: signInDelegateSpy)
84+
85+
sut.signIn(username: username, password: "An Invalid Password", correlationId: correlationId, delegate: signInDelegateSpy)
9286

9387
await fulfillment(of: [signInExpectation])
9488

@@ -114,6 +108,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
114108
let signInParam = MSALNativeAuthSignInParameters(username: username)
115109
signInParam.password = password
116110
signInParam.correlationId = correlationId
111+
117112
sut.signIn(parameters: signInParam, delegate: signInDelegateSpy)
118113

119114
await fulfillment(of: [signInExpectation])
@@ -126,10 +121,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
126121
let signInExpectation2 = expectation(description: "signing in")
127122
let signInDelegateSpy2 = SignInPasswordStartDelegateSpy(expectation: signInExpectation2)
128123

129-
let signInParam2 = MSALNativeAuthSignInParameters(username: username)
130-
signInParam2.password = password
131-
signInParam2.correlationId = correlationId
132-
sut.signIn(parameters: signInParam2, delegate: signInDelegateSpy2)
124+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy2)
133125

134126
XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
135127
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
@@ -148,10 +140,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
148140
let signInExpectation = expectation(description: "signing in")
149141
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
150142

151-
let signInParam = MSALNativeAuthSignInParameters(username: username)
152-
signInParam.password = password
153-
signInParam.correlationId = correlationId
154-
sut.signIn(parameters: signInParam, delegate: signInDelegateSpy)
143+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
155144

156145
await fulfillment(of: [signInExpectation])
157146

@@ -163,9 +152,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
163152
let signInExpectation2 = expectation(description: "signing in")
164153
let signInDelegateSpy2 = SignInStartDelegateSpy(expectation: signInExpectation)
165154

166-
let signInParam2 = MSALNativeAuthSignInParameters(username: username2)
167-
signInParam2.correlationId = correlationId
168-
sut.signIn(parameters: signInParam2, delegate: signInDelegateSpy2)
155+
sut.signIn(username: username2, correlationId: correlationId, delegate: signInDelegateSpy2)
169156

170157
await fulfillment(of: [signInExpectation2])
171158

@@ -194,11 +181,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
194181
/* User Case 1.2.6. Sign In - Ability to provide scope to control auth strength of the token
195182
Please refer to Crendentials test (test_signInWithExtraScopes())
196183

197-
let signInParam = MSALNativeAuthSignInParameters(username: username)
198-
signInParam.password = password
199-
signInParam.correlationId = correlationId
200-
sut.signIn(parameters: signInParam, delegate: signInDelegateSpy)
201-
184+
sut.signIn(username: username, password: password, scopes: ["User.Read"], correlationId: correlationId, delegate: signInDelegateSpy)
202185
...
203186
XCTAssertTrue(credentialsDelegateSpy.result!.scopes.contains("User.Read"))
204187
*/
@@ -215,10 +198,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
215198
let signInExpectation = expectation(description: "signing in")
216199
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation)
217200

218-
let signInParam = MSALNativeAuthSignInParameters(username: username)
219-
signInParam.password = password
220-
signInParam.correlationId = correlationId
221-
sut.signIn(parameters: signInParam, delegate: signInDelegateSpy)
201+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
222202

223203
await fulfillment(of: [signInExpectation])
224204

0 commit comments

Comments
 (0)