-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sign in with id token method (#49)
* Add sign in with id token method * Add test * ci: copy secrets file * Format and fix tests * Add deprecations * Fix initializer
- Loading branch information
Showing
11 changed files
with
123 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--swiftversion 5.7 | ||
--binarygrouping none | ||
--decimalgrouping none | ||
--hexgrouping none | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
extension GoTrueMetaSecurity { | ||
@available(*, deprecated, renamed: "captchaToken") | ||
public var hcaptchaToken: String { | ||
get { captchaToken } | ||
set { captchaToken = newValue } | ||
} | ||
|
||
@available(*, deprecated, renamed: "init(captchaToken:)") | ||
public init(hcaptchaToken: String) { | ||
self.init(captchaToken: hcaptchaToken) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,20 +40,32 @@ final class GoTrueTests: XCTestCase { | |
func testDecodeSessionOrUser() { | ||
XCTAssertNoThrow( | ||
try JSONDecoder.goTrue.decode( | ||
AuthResponse.self, from: sessionJSON.data(using: .utf8)! | ||
AuthResponse.self, from: json(named: "session") | ||
) | ||
) | ||
} | ||
|
||
#if !os(watchOS) | ||
// Not working on watchOS, don't know why. | ||
func test_signUpWithEmailAndPassword() async throws { | ||
Mock.post(path: "signup", json: "signup-response").register() | ||
|
||
let user = try await sut.signUp(email: "[email protected]", password: "thepass").user | ||
|
||
XCTAssertEqual(user?.email, "[email protected]") | ||
} | ||
|
||
func testSignInWithIdToken() async throws { | ||
Mock( | ||
url: URL(string: "http://localhost:54321/auth/v1/token?grant_type=id_token")!, | ||
dataType: .json, | ||
statusCode: 200, | ||
data: [.post: json(named: "session")] | ||
).register() | ||
|
||
let session = try await sut | ||
.signInWithIdToken(credentials: OpenIDConnectCredentials(token: "dummy-token-1234")) | ||
XCTAssertEqual(session.user.email, "[email protected]") | ||
} | ||
#endif | ||
|
||
func testSignInWithProvider() throws { | ||
|
@@ -110,43 +122,3 @@ final class GoTrueTests: XCTestCase { | |
} | ||
} | ||
} | ||
|
||
let sessionJSON = """ | ||
{ | ||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjQ4NjQwMDIxLCJzdWIiOiJmMzNkM2VjOS1hMmVlLTQ3YzQtODBlMS01YmQ5MTlmM2Q4YjgiLCJlbWFpbCI6Imd1aWxoZXJtZTJAZ3Jkcy5kZXYiLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQifQ.4lMvmz2pJkWu1hMsBgXP98Fwz4rbvFYl4VA9joRv6kY", | ||
"token_type": "bearer", | ||
"expires_in": 3600, | ||
"refresh_token": "GGduTeu95GraIXQ56jppkw", | ||
"user": { | ||
"id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"aud": "authenticated", | ||
"role": "authenticated", | ||
"email": "[email protected]", | ||
"email_confirmed_at": "2022-03-30T10:33:41.018575157Z", | ||
"phone": "", | ||
"last_sign_in_at": "2022-03-30T10:33:41.021531328Z", | ||
"app_metadata": { | ||
"provider": "email", | ||
"providers": [ | ||
"email" | ||
] | ||
}, | ||
"user_metadata": {}, | ||
"identities": [ | ||
{ | ||
"id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"user_id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"identity_data": { | ||
"sub": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8" | ||
}, | ||
"provider": "email", | ||
"last_sign_in_at": "2022-03-30T10:33:41.015557063Z", | ||
"created_at": "2022-03-30T10:33:41.015612Z", | ||
"updated_at": "2022-03-30T10:33:41.015616Z" | ||
} | ||
], | ||
"created_at": "2022-03-30T10:33:41.005433Z", | ||
"updated_at": "2022-03-30T10:33:41.022688Z" | ||
} | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjQ4NjQwMDIxLCJzdWIiOiJmMzNkM2VjOS1hMmVlLTQ3YzQtODBlMS01YmQ5MTlmM2Q4YjgiLCJlbWFpbCI6Imd1aWxoZXJtZTJAZ3Jkcy5kZXYiLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQifQ.4lMvmz2pJkWu1hMsBgXP98Fwz4rbvFYl4VA9joRv6kY", | ||
"token_type": "bearer", | ||
"expires_in": 3600, | ||
"refresh_token": "GGduTeu95GraIXQ56jppkw", | ||
"user": { | ||
"id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"aud": "authenticated", | ||
"role": "authenticated", | ||
"email": "[email protected]", | ||
"email_confirmed_at": "2022-03-30T10:33:41.018575157Z", | ||
"phone": "", | ||
"last_sign_in_at": "2022-03-30T10:33:41.021531328Z", | ||
"app_metadata": { | ||
"provider": "email", | ||
"providers": [ | ||
"email" | ||
] | ||
}, | ||
"user_metadata": {}, | ||
"identities": [ | ||
{ | ||
"id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"user_id": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8", | ||
"identity_data": { | ||
"sub": "f33d3ec9-a2ee-47c4-80e1-5bd919f3d8b8" | ||
}, | ||
"provider": "email", | ||
"last_sign_in_at": "2022-03-30T10:33:41.015557063Z", | ||
"created_at": "2022-03-30T10:33:41.015612Z", | ||
"updated_at": "2022-03-30T10:33:41.015616Z" | ||
} | ||
], | ||
"created_at": "2022-03-30T10:33:41.005433Z", | ||
"updated_at": "2022-03-30T10:33:41.022688Z" | ||
} | ||
} |