Skip to content

Commit bf4e390

Browse files
ncooke3pragatimodi
authored andcommitted
[v11] Deprecate OAuthProvider API get credential API that uses string provider ID (#13097)
1 parent 495f0e0 commit bf4e390

File tree

3 files changed

+132
-17
lines changed

3 files changed

+132
-17
lines changed

FirebaseAuth/Sources/Swift/AuthProvider/OAuthProvider.swift

Lines changed: 110 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,104 @@ import Foundation
9191
/// - Parameter accessToken: The access token associated with the Auth credential be created, if
9292
/// available.
9393
/// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
94+
@available(swift, introduced: 100.0)
9495
@objc(credentialWithProviderID:IDToken:accessToken:)
96+
public static func credential(withProviderID providerID: NSString,
97+
idToken: NSString,
98+
accessToken: NSString?) -> OAuthCredential {
99+
return OAuthCredential(
100+
withProviderID: providerID as String,
101+
idToken: idToken as String,
102+
accessToken: accessToken as String?
103+
)
104+
}
105+
106+
@available(
107+
*,
108+
deprecated,
109+
message: "Use `credential(providerID: AuthProviderID, idToken: String, accessToken: String) -> OAuthCredential` instead."
110+
)
95111
public static func credential(withProviderID providerID: String,
96112
idToken: String,
97113
accessToken: String?) -> OAuthCredential {
98114
return OAuthCredential(withProviderID: providerID, idToken: idToken, accessToken: accessToken)
99115
}
100116

117+
/// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID, ID
118+
/// token, and access token.
119+
/// - Parameter providerID: The provider ID associated with the Auth credential being created.
120+
/// - Parameter idToken: The IDToken associated with the Auth credential being created.
121+
/// - Parameter accessToken: The access token associated with the Auth credential be created, if
122+
/// available.
123+
/// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
124+
public static func credential(providerID: AuthProviderID,
125+
idToken: String,
126+
accessToken: String?) -> OAuthCredential {
127+
return OAuthCredential(
128+
withProviderID: providerID.rawValue,
129+
idToken: idToken,
130+
accessToken: accessToken
131+
)
132+
}
133+
134+
/// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID, ID
135+
/// token, and access token.
136+
/// - Parameter providerID: The provider ID associated with the Auth credential being created.
137+
/// - Parameter accessToken: The access token associated with the Auth credential be created, if
138+
/// available.
139+
/// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
140+
@available(swift, introduced: 100.0)
141+
@objc(credentialWithProviderID:accessToken:)
142+
public static func credential(withProviderID providerID: NSString,
143+
accessToken: NSString) -> OAuthCredential {
144+
return OAuthCredential(withProviderID: providerID as String, accessToken: accessToken as String)
145+
}
146+
147+
@available(
148+
*,
149+
deprecated,
150+
message: "Use `credential(providerID: AuthProviderID, accessToken: String) -> OAuthCredential` instead."
151+
)
152+
public static func credential(withProviderID providerID: String,
153+
accessToken: String) -> OAuthCredential {
154+
return OAuthCredential(withProviderID: providerID, accessToken: accessToken)
155+
}
156+
101157
/// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID using
102158
/// an ID token.
103159
/// - Parameter providerID: The provider ID associated with the Auth credential being created.
104160
/// - Parameter accessToken: The access token associated with the Auth credential be created
105161
/// - Returns: An AuthCredential.
106-
@objc(credentialWithProviderID:accessToken:)
107-
public static func credential(withProviderID providerID: String,
162+
public static func credential(providerID: AuthProviderID,
108163
accessToken: String) -> OAuthCredential {
109-
return OAuthCredential(withProviderID: providerID, accessToken: accessToken)
164+
return OAuthCredential(withProviderID: providerID.rawValue, accessToken: accessToken)
110165
}
111166

112167
/// Creates an `AuthCredential` for that OAuth 2 provider identified by provider ID, ID
113168
/// token, raw nonce, and access token.
114169
/// - Parameter providerID: The provider ID associated with the Auth credential being created.
115170
/// - Parameter idToken: The IDToken associated with the Auth credential being created.
116171
/// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
117-
/// - Parameter accessToken: The access token associated with the Auth credential be created, if
118-
/// available.
172+
/// - Parameter accessToken: The access token associated with the Auth credential be created.
119173
/// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
174+
@available(swift, introduced: 100.0)
120175
@objc(credentialWithProviderID:IDToken:rawNonce:accessToken:)
176+
public static func credential(withProviderID providerID: NSString, idToken: NSString,
177+
rawNonce: NSString,
178+
accessToken: NSString) -> OAuthCredential {
179+
return OAuthCredential(
180+
withProviderID: providerID as String,
181+
idToken: idToken as String,
182+
rawNonce: rawNonce as String,
183+
accessToken: accessToken as String
184+
)
185+
}
186+
187+
@available(
188+
*,
189+
deprecated,
190+
message: "Use `credential(providerID: AuthProviderID, rawNonce: String, accessToken: String) -> OAuthCredential` instead."
191+
)
121192
public static func credential(withProviderID providerID: String, idToken: String,
122193
rawNonce: String,
123194
accessToken: String) -> OAuthCredential {
@@ -135,12 +206,46 @@ import Foundation
135206
/// - Parameter idToken: The IDToken associated with the Auth credential being created.
136207
/// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
137208
/// - Returns: An AuthCredential.
209+
@available(swift, introduced: 100.0)
138210
@objc(credentialWithProviderID:IDToken:rawNonce:)
211+
public static func credential(withProviderID providerID: NSString, idToken: NSString,
212+
rawNonce: NSString) -> OAuthCredential {
213+
return OAuthCredential(
214+
withProviderID: providerID as String,
215+
idToken: idToken as String,
216+
rawNonce: rawNonce as String
217+
)
218+
}
219+
220+
@available(
221+
*,
222+
deprecated,
223+
message: "Use `credential(providerID: AuthProviderID, idToken: String, rawNonce: String) -> OAuthCredential` instead."
224+
)
139225
public static func credential(withProviderID providerID: String, idToken: String,
140226
rawNonce: String) -> OAuthCredential {
141227
return OAuthCredential(withProviderID: providerID, idToken: idToken, rawNonce: rawNonce)
142228
}
143229

230+
/// Creates an `AuthCredential` for that OAuth 2 provider identified by provider ID, ID
231+
/// token, raw nonce, and access token.
232+
/// - Parameter providerID: The provider ID associated with the Auth credential being created.
233+
/// - Parameter idToken: The IDToken associated with the Auth credential being created.
234+
/// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
235+
/// - Parameter accessToken: The access token associated with the Auth credential be created, if
236+
/// available.
237+
/// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
238+
public static func credential(providerID: AuthProviderID, idToken: String,
239+
rawNonce: String,
240+
accessToken: String? = nil) -> OAuthCredential {
241+
return OAuthCredential(
242+
withProviderID: providerID.rawValue,
243+
idToken: idToken,
244+
rawNonce: rawNonce,
245+
accessToken: accessToken
246+
)
247+
}
248+
144249
#if os(iOS)
145250
/// Used to obtain an auth credential via a mobile web flow.
146251
///

FirebaseAuth/Tests/Unit/OAuthProviderTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ import FirebaseCore
5555
*/
5656
func testObtainingOAuthCredentialNoIDToken() throws {
5757
initApp(#function)
58-
let credential = OAuthProvider.credential(withProviderID: kFakeProviderID,
58+
let credential = OAuthProvider.credential(providerID: .apple,
5959
accessToken: kFakeAccessToken)
6060
XCTAssertEqual(credential.accessToken, kFakeAccessToken)
61-
XCTAssertEqual(credential.provider, kFakeProviderID)
61+
XCTAssertEqual(credential.provider, AuthProviderID.apple.rawValue)
6262
XCTAssertNil(credential.idToken)
6363
}
6464

@@ -85,11 +85,11 @@ import FirebaseCore
8585
*/
8686
func testObtainingOAuthCredentialWithIDToken() throws {
8787
initApp(#function)
88-
let credential = OAuthProvider.credential(withProviderID: kFakeProviderID,
88+
let credential = OAuthProvider.credential(providerID: .email,
8989
idToken: kFakeIDToken,
9090
accessToken: kFakeAccessToken)
9191
XCTAssertEqual(credential.accessToken, kFakeAccessToken)
92-
XCTAssertEqual(credential.provider, kFakeProviderID)
92+
XCTAssertEqual(credential.provider, AuthProviderID.email.rawValue)
9393
XCTAssertEqual(credential.idToken, kFakeIDToken)
9494
}
9595

FirebaseAuth/Tests/Unit/SwiftAPI.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,24 @@ class AuthAPI_hOnlyTests: XCTestCase {
472472
let provider = OAuthProvider(providerID: "id", auth: FirebaseAuth.Auth.auth())
473473
_ = provider.providerID
474474
#if os(iOS)
475-
_ = OAuthProvider.credential(withProviderID: "id", idToken: "idToden", accessToken: "token")
476-
_ = OAuthProvider.credential(withProviderID: "id", accessToken: "token")
477-
_ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce",
478-
accessToken: "token")
479-
_ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce")
480-
_ = OAuthProvider.appleCredential(withIDToken: "idToken",
481-
rawNonce: "nonce",
482-
fullName: nil)
475+
let _: (String, String, String?) -> OAuthCredential =
476+
OAuthProvider.credential(withProviderID:idToken:accessToken:)
477+
let _: (AuthProviderID, String, String?) -> OAuthCredential =
478+
OAuthProvider.credential(providerID:idToken:accessToken:)
479+
let _: (String, String) -> OAuthCredential =
480+
OAuthProvider.credential(withProviderID:accessToken:)
481+
let _: (AuthProviderID, String) -> OAuthCredential = OAuthProvider
482+
.credential(providerID:accessToken:)
483+
let _: (String, String, String, String) -> OAuthCredential =
484+
OAuthProvider.credential(withProviderID:idToken:rawNonce:accessToken:)
485+
let _: (AuthProviderID, String, String, String?) -> OAuthCredential =
486+
OAuthProvider.credential(providerID:idToken:rawNonce:accessToken:)
487+
// `accessToken` defaults to `nil`
488+
let _: OAuthCredential =
489+
OAuthProvider.credential(providerID: .apple, idToken: "", rawNonce: "")
490+
let _: (String, String, String) -> OAuthCredential =
491+
OAuthProvider.credential(withProviderID:idToken:rawNonce:)
492+
483493
provider.getCredentialWith(provider as? AuthUIDelegate) { credential, error in
484494
}
485495
#endif

0 commit comments

Comments
 (0)