-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
350 additions
and
174 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
303 changes: 165 additions & 138 deletions
303
Authorization/Authorization/Presentation/Login/SignInView.swift
Large diffs are not rendered by default.
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
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 |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
// | ||
|
||
import Foundation | ||
import OAuthSwift | ||
|
||
public protocol AuthRepositoryProtocol { | ||
func login(credential: OAuthSwiftCredential) async throws -> User | ||
func login(username: String, password: String) async throws -> User | ||
func login(externalToken: String, backend: String) async throws -> User | ||
func getCookies(force: Bool) async throws | ||
|
@@ -29,6 +31,17 @@ public class AuthRepository: AuthRepositoryProtocol { | |
self.config = config | ||
} | ||
|
||
public func login(credential: OAuthSwiftCredential) async throws -> User { | ||
// Login for when we have the accessToken and refreshToken directly, like from web-view | ||
// OAuth logins. | ||
appStorage.cookiesDate = nil | ||
appStorage.accessToken = credential.oauthToken | ||
appStorage.refreshToken = credential.oauthRefreshToken | ||
let user = try await api.requestData(AuthEndpoint.getUserInfo).mapResponse(DataLayer.User.self) | ||
appStorage.user = user | ||
return user.domain | ||
} | ||
|
||
public func login(username: String, password: String) async throws -> User { | ||
appStorage.cookiesDate = nil | ||
let endPoint = AuthEndpoint.getAccessToken( | ||
|
@@ -130,6 +143,11 @@ public class AuthRepository: AuthRepositoryProtocol { | |
// Mark - For testing and SwiftUI preview | ||
#if DEBUG | ||
class AuthRepositoryMock: AuthRepositoryProtocol { | ||
|
||
func login(credential: OAuthSwiftCredential) async throws -> User { | ||
User(id: 1, username: "User", email: "[email protected]", name: "User Name", userAvatar: "") | ||
} | ||
|
||
func login(username: String, password: String) async throws -> User { | ||
User(id: 1, username: "User", email: "[email protected]", name: "User Name", userAvatar: "") | ||
} | ||
|
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
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
Oops, something went wrong.