Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct auth keys for Facebook and Twitter login #202

Merged
merged 5 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ __Improvements__
- Clear caching when a user logs out ([#198](https://github.com/parse-community/Parse-Swift/pull/198)), thanks to [Corey Baker](https://github.com/cbaker6).
- Close all LiveQuery connections when a user logs out ([#199](https://github.com/parse-community/Parse-Swift/pull/199)), thanks to [Corey Baker](https://github.com/cbaker6).

__Fixes__
- Fix Facebook and Twitter login setting incorrect keys ([#202](https://github.com/parse-community/Parse-Swift/pull/202)), thanks to [Daniel Blyth](https://github.com/dblythy).

### 1.9.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.6...1.9.0)

Expand Down Expand Up @@ -44,7 +47,7 @@ __Improvements__
__Fixes__
- Fixed a bug in LiveQuery when a close frame is sent from the server that resulted in closing
all running websocket tasks instead of the particular task the request was intended for. The fix
includes a new delegate method named `closedSocket()` which provides the close code
includes a new delegate method named `closedSocket()` which provides the close code
and reason the server closed the connection ([#176](https://github.com/parse-community/Parse-Swift/pull/176)), thanks to [Corey Baker](https://github.com/cbaker6).

### 1.8.4
Expand Down
13 changes: 3 additions & 10 deletions Sources/ParseSwift/Authentication/3rd Party/ParseFacebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Authentication keys required for Facebook authentication.
enum AuthenticationKeys: String, Codable {
case id // swiftlint:disable:this identifier_name
case authenticationToken
case accessToken
case expirationDate

enum CodingKeys: String, CodingKey { // swiftlint:disable:this nesting
case id // swiftlint:disable:this identifier_name
case authenticationToken = "token"
case accessToken = "access_token"
case expirationDate = "expiration_date"
}
case authenticationToken = "token"
case accessToken = "access_token"
case expirationDate = "expiration_date"

/// Properly makes an authData dictionary with the required keys.
/// - parameter userId: Required id for the user.
Expand Down
19 changes: 5 additions & 14 deletions Sources/ParseSwift/Authentication/3rd Party/ParseTwitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,11 @@ public struct ParseTwitter<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Authentication keys required for Twitter authentication.
enum AuthenticationKeys: String, Codable {
case id // swiftlint:disable:this identifier_name
case consumerKey
case consumerSecret
case authToken
case authTokenSecret
case screenName

enum CodingKeys: String, CodingKey { // swiftlint:disable:this nesting
case id // swiftlint:disable:this identifier_name
case consumerKey = "consumer_key"
case consumerSecret = "consumer_secret"
case authToken = "auth_token"
case authTokenSecret = "auth_token_secret"
case screenName = "screen_name"
}
case consumerKey = "consumer_key"
case consumerSecret = "consumer_secret"
case authToken = "auth_token"
case authTokenSecret = "auth_token_secret"
case screenName = "screen_name"

/// Properly makes an authData dictionary with the required keys.
/// - parameter userId: Required id.
Expand Down
1 change: 0 additions & 1 deletion Tests/ParseSwiftTests/ParseFacebookCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class ParseFacebookCombineTests: XCTestCase { // swiftlint:disable:this type_bod
#endif
try ParseStorage.shared.deleteAll()
}

func testLimitedLogin() {
var subscriptions = Set<AnyCancellable>()
let expectation1 = XCTestExpectation(description: "Save")
Expand Down
22 changes: 11 additions & 11 deletions Tests/ParseSwiftTests/ParseFacebookTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ParseFacebookTests: XCTestCase {
accessToken: nil,
authenticationToken: "authenticationToken")
XCTAssertEqual(authData, ["id": "testing",
"authenticationToken": "authenticationToken"])
"token": "authenticationToken"])
}

func testAuthenticationKeysLimitedLoginExpires() throws {
Expand All @@ -111,33 +111,33 @@ class ParseFacebookTests: XCTestCase {
accessToken: nil,
authenticationToken: "authenticationToken",
expiresIn: expiresIn)
guard let dateString = authData["expirationDate"] else {
guard let dateString = authData["expiration_date"] else {
XCTFail("Should have found date")
return
}
XCTAssertEqual(authData, ["id": "testing",
"authenticationToken": "authenticationToken",
"expirationDate": dateString])
"token": "authenticationToken",
"expiration_date": dateString])
}

func testVerifyMandatoryKeys() throws {
let authData = ["id": "testing",
"authenticationToken": "authenticationToken"]
"token": "authenticationToken"]
XCTAssertTrue(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authData))
let authData2 = ["id": "testing",
"accessToken": "accessToken"]
"access_token": "accessToken"]
XCTAssertTrue(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authData2))
XCTAssertTrue(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authData))
let authDataWrong = ["id": "testing", "hello": "test"]
XCTAssertFalse(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authDataWrong))
let authDataWrong2 = ["world": "testing", "authenticationToken": "test"]
let authDataWrong2 = ["world": "testing", "token": "test"]
XCTAssertFalse(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authDataWrong2))
let authDataWrong3 = ["world": "testing", "accessToken": "test"]
let authDataWrong3 = ["world": "testing", "access_token": "test"]
XCTAssertFalse(ParseFacebook<User>
.AuthenticationKeys.id.verifyMandatoryKeys(authData: authDataWrong3))
}
Expand All @@ -147,7 +147,7 @@ class ParseFacebookTests: XCTestCase {
.AuthenticationKeys.id.makeDictionary(userId: "testing",
accessToken: "accessToken",
authenticationToken: nil)
XCTAssertEqual(authData, ["id": "testing", "accessToken": "accessToken"])
XCTAssertEqual(authData, ["id": "testing", "access_token": "accessToken"])
}

func testAuthenticationKeysGraphAPILoginExpires() throws {
Expand All @@ -157,11 +157,11 @@ class ParseFacebookTests: XCTestCase {
accessToken: "accessToken",
authenticationToken: nil,
expiresIn: expiresIn)
guard let dateString = authData["expirationDate"] else {
guard let dateString = authData["expiration_date"] else {
XCTFail("Should have found date")
return
}
XCTAssertEqual(authData, ["id": "testing", "accessToken": "accessToken", "expirationDate": dateString])
XCTAssertEqual(authData, ["id": "testing", "access_token": "accessToken", "expiration_date": dateString])
}

func testLimitedLogin() throws {
Expand Down
20 changes: 10 additions & 10 deletions Tests/ParseSwiftTests/ParseTwitterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ class ParseTwitterTests: XCTestCase {
authToken: "authToken",
authTokenSecret: "authTokenSecret")
XCTAssertEqual(authData, ["id": "testing",
"screenName": "screenName",
"consumerKey": "consumerKey",
"consumerSecret": "consumerSecret",
"authToken": "authToken",
"authTokenSecret": "authTokenSecret"])
"screen_name": "screenName",
"consumer_key": "consumerKey",
"consumer_secret": "consumerSecret",
"auth_token": "authToken",
"auth_token_secret": "authTokenSecret"])
}

func testVerifyMandatoryKeys() throws {
let authData = ["id": "testing",
"screenName": "screenName",
"consumerKey": "consumerKey",
"consumerSecret": "consumerSecret",
"authToken": "authToken",
"authTokenSecret": "authTokenSecret"]
"screen_name": "screenName",
"consumer_key": "consumerKey",
"consumer_secret": "consumerSecret",
"auth_token": "authToken",
"auth_token_secret": "authTokenSecret"]
let authDataWrong = ["id": "testing",
"screenName": "screenName",
"consumerKey": "consumerKey",
Expand Down