-
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
15 changed files
with
318 additions
and
124 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
270 changes: 152 additions & 118 deletions
270
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ public class Config { | |
|
||
public let baseURL: URL | ||
public let oAuthClientId: String | ||
public let webLogin: Bool | ||
|
||
public lazy var termsOfUse: URL? = { | ||
URL(string: "\(baseURL.description)/tos") | ||
|
@@ -22,20 +23,21 @@ public class Config { | |
|
||
public let feedbackEmail = "[email protected]" | ||
|
||
public init(baseURL: String, oAuthClientId: String) { | ||
public init(baseURL: String, oAuthClientId: String, webLogin: Bool) { | ||
guard let url = URL(string: baseURL) else { | ||
fatalError("Ivalid baseURL") | ||
} | ||
self.baseURL = url | ||
self.oAuthClientId = oAuthClientId | ||
self.webLogin = webLogin | ||
} | ||
} | ||
|
||
// Mark - For testing and SwiftUI preview | ||
#if DEBUG | ||
public class ConfigMock: Config { | ||
public convenience init() { | ||
self.init(baseURL: "https://google.com/", oAuthClientId: "client_id") | ||
self.init(baseURL: "https://google.com/", oAuthClientId: "client_id", webLogin: false) | ||
} | ||
} | ||
#endif |
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 getCookies(force: Bool) async throws | ||
func getRegistrationFields() async throws -> [PickerFields] | ||
|
@@ -28,6 +30,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( | ||
|
@@ -100,6 +113,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
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