Delete FeedlyAccountDelegate+OAuth.swift.

This commit is contained in:
Brent Simmons 2024-05-01 20:49:09 -07:00
parent 0a4be8f49f
commit e56f7a73b8
3 changed files with 18 additions and 34 deletions

View File

@ -1,33 +0,0 @@
//
// FeedlyAccountDelegate+OAuth.swift
// Account
//
// Created by Kiel Gillard on 14/9/19.
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import Web
import Secrets
import Feedly
extension FeedlyAccountDelegate {
func refreshAccessToken(with refreshToken: String, client: OAuthAuthorizationClient) async throws -> OAuthAuthorizationGrant {
let request = OAuthRefreshAccessTokenRequest(refreshToken: refreshToken, scope: nil, client: client)
let response = try await caller.refreshAccessToken(request)
let accessToken = Credentials(type: .oauthAccessToken, username: response.id, secret: response.accessToken)
let refreshToken: Credentials? = {
guard let token = response.refreshToken else {
return nil
}
return Credentials(type: .oauthRefreshToken, username: response.id, secret: token)
}()
let grant = OAuthAuthorizationGrant(accessToken: accessToken, refreshToken: refreshToken)
return grant
}
}

View File

@ -964,7 +964,7 @@ extension FeedlyAccountDelegate: FeedlyAPICallerDelegate {
}
os_log(.debug, log: log, "Refreshing access token.")
let grant = try await refreshAccessToken(with: credentials.secret, client: oauthAuthorizationClient)
let grant = try await caller.refreshAccessToken(with: credentials.secret, client: oauthAuthorizationClient)
os_log(.debug, log: log, "Storing refresh token.")
if let refreshToken = grant.refreshToken {

View File

@ -617,6 +617,23 @@ extension FeedlyAPICaller {
return grant
}
public func refreshAccessToken(with refreshToken: String, client: OAuthAuthorizationClient) async throws -> OAuthAuthorizationGrant {
let request = OAuthRefreshAccessTokenRequest(refreshToken: refreshToken, scope: nil, client: client)
let response = try await refreshAccessToken(request)
let accessToken = Credentials(type: .oauthAccessToken, username: response.id, secret: response.accessToken)
let refreshToken: Credentials? = {
guard let token = response.refreshToken else {
return nil
}
return Credentials(type: .oauthRefreshToken, username: response.id, secret: token)
}()
let grant = OAuthAuthorizationGrant(accessToken: accessToken, refreshToken: refreshToken)
return grant
}
}
private extension FeedlyAPICaller {