Fetches Patreon creator access token from AltStore source

This commit is contained in:
Riley Testut
2019-11-04 13:42:19 -08:00
parent f10f519eab
commit b194b4b642
9 changed files with 51 additions and 2 deletions

View File

@@ -5,3 +5,4 @@
#import "NSError+ALTServerError.h"
#import "ALTAppPermission.h"
#import "ALTPatreonBenefitType.h"
#import "ALTSourceUserInfoKey.h"

View File

@@ -71,6 +71,9 @@ class Keychain
@KeychainItem(key: "patreonRefreshToken")
var patreonRefreshToken: String?
@KeychainItem(key: "patreonCreatorAccessToken")
var patreonCreatorAccessToken: String?
private init()
{
}

View File

@@ -27,6 +27,9 @@ class Source: NSManagedObject, Fetchable, Decodable
@NSManaged var identifier: String
@NSManaged var sourceURL: URL
/* Non-Core Data Properties */
var userInfo: [ALTSourceUserInfoKey: String]?
/* Relationships */
@objc(apps) @NSManaged private(set) var _apps: NSOrderedSet
@objc(newsItems) @NSManaged private(set) var _newsItems: NSOrderedSet
@@ -54,6 +57,7 @@ class Source: NSManagedObject, Fetchable, Decodable
case name
case identifier
case sourceURL
case userInfo
case apps
case news
}
@@ -74,6 +78,9 @@ class Source: NSManagedObject, Fetchable, Decodable
self.identifier = try container.decode(String.self, forKey: .identifier)
self.sourceURL = try container.decode(URL.self, forKey: .sourceURL)
let userInfo = try container.decodeIfPresent([String: String].self, forKey: .userInfo)
self.userInfo = userInfo?.reduce(into: [:]) { $0[ALTSourceUserInfoKey($1.key)] = $1.value }
let apps = try container.decodeIfPresent([StoreApp].self, forKey: .apps) ?? []
for (index, app) in apps.enumerated()
{

View File

@@ -68,6 +68,11 @@ class FetchSourceOperation: ResultOperation<Source>
let source = try decoder.decode(Source.self, from: data)
if let patreonAccessToken = source.userInfo?[.patreonAccessToken]
{
Keychain.shared.patreonCreatorAccessToken = patreonAccessToken
}
#if STAGING
source.sourceURL = self.sourceURL
#endif

View File

@@ -11,7 +11,6 @@ import AuthenticationServices
private let clientID = "ZMx0EGUWe4TVWYXNZZwK_fbIK5jHFVWoUf1Qb-sqNXmT-YzAGwDPxxq7ak3_W5Q2"
private let clientSecret = "1hktsZB89QyN69cB4R0tu55R4TCPQGXxvebYUUh7Y-5TLSnRswuxs6OUjdJ74IJt"
private let creatorAccessToken = "NSX1ts9Rf9IzKRCu8GjbwsZ6wll8bDtoJxNbPbp2eZo"
private let campaignID = "2863968"
@@ -348,7 +347,9 @@ private extension PatreonAPI
{
case .none: break
case .creator:
guard let creatorAccessToken = Keychain.shared.patreonCreatorAccessToken else { return completion(.failure(Error.invalidAccessToken)) }
request.setValue("Bearer " + creatorAccessToken, forHTTPHeaderField: "Authorization")
case .user:
guard let accessToken = Keychain.shared.patreonAccessToken else { return completion(.failure(Error.notAuthenticated)) }
request.setValue("Bearer " + accessToken, forHTTPHeaderField: "Authorization")

View File

@@ -202,5 +202,8 @@
"date": "2019-10-09",
"notify": false
}
]
],
"userInfo": {
"patreonAccessToken": "lb2Sq14mVCejEtITnlGfszbYXDhXmrdpiOMCEZjlfFk"
}
}

View File

@@ -0,0 +1,12 @@
//
// ALTSourceUserInfoKey.h
// AltStore
//
// Created by Riley Testut on 11/4/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NSString *ALTSourceUserInfoKey NS_TYPED_EXTENSIBLE_ENUM;
extern ALTSourceUserInfoKey const ALTSourceUserInfoKeyPatreonAccessToken;

View File

@@ -0,0 +1,11 @@
//
// ALTSourceUserInfoKey.m
// AltStore
//
// Created by Riley Testut on 11/4/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
#import "ALTSourceUserInfoKey.h"
ALTSourceUserInfoKey const ALTSourceUserInfoKeyPatreonAccessToken = @"patreonAccessToken";