Ensure credentials are available for use
Need to load metadad first
This commit is contained in:
parent
aa6dfe8a08
commit
fdc0374c4f
@ -263,9 +263,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
public func storeCredentials(_ credentials: Credentials) throws {
|
public func storeCredentials(_ credentials: Credentials) throws {
|
||||||
// The delegate may need the credentials to determine the server
|
|
||||||
delegate.credentials = credentials
|
|
||||||
|
|
||||||
guard let server = delegate.server else {
|
guard let server = delegate.server else {
|
||||||
throw CredentialsError.incompleteCredentials
|
throw CredentialsError.incompleteCredentials
|
||||||
}
|
}
|
||||||
@ -300,6 +297,21 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
self.username = nil
|
self.username = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func retrieveGoogleAuthCredentials() throws -> Credentials? {
|
||||||
|
guard let username = self.username, let server = delegate.server else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return try CredentialsManager.retrieveGoogleAuthCredentials(server: server, username: username)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func removeGoogleAuthCredentials() throws {
|
||||||
|
guard let username = self.username, let server = delegate.server else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try CredentialsManager.removeGoogleAuthCredentials(server: server, username: username)
|
||||||
|
self.username = nil
|
||||||
|
}
|
||||||
|
|
||||||
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
||||||
switch type {
|
switch type {
|
||||||
case .onMyMac:
|
case .onMyMac:
|
||||||
|
@ -163,7 +163,21 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let callURL = baseURL.appendingPathComponent("/reader/api/0/tag/list?output=json")
|
// Add query string for getting JSON (probably should break this out as I will be doing it a lot)
|
||||||
|
guard var components = URLComponents(url: baseURL.appendingPathComponent("/reader/api/0/tag/list"), resolvingAgainstBaseURL: false) else {
|
||||||
|
completion(.failure(TransportError.noURL))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
components.queryItems = [
|
||||||
|
URLQueryItem(name: "output", value: "json")
|
||||||
|
]
|
||||||
|
|
||||||
|
guard let callURL = components.url else {
|
||||||
|
completion(.failure(TransportError.noURL))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
|
//let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
|
||||||
let request = URLRequest(url: callURL, credentials: credentials)
|
let request = URLRequest(url: callURL, credentials: credentials)
|
||||||
|
|
||||||
|
@ -90,18 +90,22 @@ final class GoogleReaderCompatibleAccountDelegate: AccountDelegate {
|
|||||||
refreshAccount(account) { result in
|
refreshAccount(account) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success():
|
case .success():
|
||||||
|
|
||||||
self.refreshArticles(account) {
|
|
||||||
self.refreshArticleStatus(for: account) {
|
|
||||||
self.refreshMissingArticles(account) {
|
|
||||||
self.refreshProgress.clear()
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// self.refreshArticles(account) {
|
||||||
|
// self.refreshArticleStatus(for: account) {
|
||||||
|
// self.refreshMissingArticles(account) {
|
||||||
|
// self.refreshProgress.clear()
|
||||||
|
// DispatchQueue.main.async {
|
||||||
|
// completion(.success(()))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.refreshProgress.clear()
|
self.refreshProgress.clear()
|
||||||
@ -486,8 +490,8 @@ final class GoogleReaderCompatibleAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func accountDidInitialize(_ account: Account) {
|
func accountDidInitialize(_ account: Account) {
|
||||||
credentials = try? account.retrieveBasicCredentials()
|
|
||||||
accountMetadata = account.metadata
|
accountMetadata = account.metadata
|
||||||
|
credentials = try? account.retrieveGoogleAuthCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
||||||
@ -570,7 +574,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
|
|
||||||
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
|
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
|
||||||
|
|
||||||
let tagNames = tags.map { $0.name }
|
let tagNames = tags.map { $0.tagID }
|
||||||
|
|
||||||
// Delete any folders not at GoogleReaderCompatible
|
// Delete any folders not at GoogleReaderCompatible
|
||||||
if let folders = account.folders {
|
if let folders = account.folders {
|
||||||
|
@ -96,10 +96,9 @@ class AccountsGoogleReaderCompatibleWindowController: NSWindowController {
|
|||||||
do {
|
do {
|
||||||
self.account?.endpointURL = apiURL
|
self.account?.endpointURL = apiURL
|
||||||
|
|
||||||
try self.account?.removeBasicCredentials()
|
try self.account?.removeGoogleAuthCredentials()
|
||||||
try self.account?.storeCredentials(validatedCredentials)
|
try self.account?.storeCredentials(validatedCredentials)
|
||||||
|
|
||||||
|
|
||||||
if newAccount {
|
if newAccount {
|
||||||
self.account?.refreshAll() { result in
|
self.account?.refreshAll() { result in
|
||||||
switch result {
|
switch result {
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit f3bcd0312d6797e2722760c1de622e2957114802
|
Subproject commit cf3a30eb3833d9dd423fed003393e6e3c1a360d4
|
Loading…
x
Reference in New Issue
Block a user