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
/* Experimenting with creating a signature to make it easier to do the server-side development. | |
See https://github.com/cloudinary/cloudinary_java/blob/master/cloudinary-core/src/main/java/com/cloudinary/Cloudinary.java#L129 | |
and https://support.cloudinary.com/hc/en-us/articles/203817991-How-to-generate-a-Cloudinary-signature-on-my-own- | |
*/ | |
// The optional timestamp is for testing this method-- this should be a UNIX timestamp with no trailing decimals-- i.e., just an integer number. | |
// Don't use "public_id" or "timestamp" as keys in otherParams if you give it. | |
func createSignature(publicId: String, apiSecret: String, otherParams: [String: Any]? = nil, timestamp: String? = nil) -> (signature: String, timestamp: String)? { | |
// 1) Set up the parameters we're going to use in the signing. | |
var params = [String: Any]() |
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
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework | |
import CommonCrypto | |
class Hashing { | |
// From https://stackoverflow.com/questions/25388747/sha256-in-swift | |
private static func sha256(data : Data) -> Data { | |
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) | |
data.withUnsafeBytes { | |
_ = CC_SHA256($0, CC_LONG(data.count), &hash) | |
} |
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
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework | |
import CommonCrypto | |
class Hashing { | |
// From https://stackoverflow.com/questions/25388747/sha256-in-swift | |
private static func sha256(data : Data) -> Data { | |
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) | |
data.withUnsafeBytes { | |
_ = CC_SHA256($0, CC_LONG(data.count), &hash) | |
} |
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
// CommonCrypto is only available with Xcode 10 for import into Swift; see also https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework | |
import CommonCrypto | |
class Hashing { | |
// From https://stackoverflow.com/questions/25388747/sha256-in-swift | |
private static func sha256(data : Data) -> Data { | |
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) | |
data.withUnsafeBytes { | |
_ = CC_SHA256($0, CC_LONG(data.count), &hash) | |
} |
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 can only be called once for a specific serverAuthCode. | |
func generateRefreshToken(serverAuthCode: String, completion: @escaping (Swift.Error?) -> ()) { | |
let clientSecret:String | |
do { | |
clientSecret = try createClientSecret() | |
} catch let error { | |
completion(error) | |
return | |
} |
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
/// Validate the given refresh token. This does *not* generate a new id token-- the API returns an updated *access token*, which Apple doesn't define a use for (and we don't save). | |
/// On success, updates the lastRefreshTokenValidation. | |
func validateRefreshToken(refreshToken: String, completion: @escaping (Swift.Error?) -> ()) { | |
self.refreshToken = refreshToken | |
let clientSecret:String | |
do { | |
clientSecret = try createClientSecret() | |
} catch let error { | |
completion(error) |
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
public struct SignInConfiguration { | |
// e.g., "https://solidcommunity.net" | |
public let issuer: String | |
// E.g., "biz.SpasticMuffin.Neebla.demo:/mypath" | |
public let redirectURI: String | |
var redirectURL: URL? { | |
return URL(string: redirectURI) | |
} |
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
/** | |
* Starts off sequence: | |
* 1) Discovery: Fetch configuration | |
* 2) Client registration | |
* 3) Authorization request | |
* 4) Get refresh token and id token | |
* 5) Get the users webid | |
* 6) Attempt to get storage IRI | |
*/ |
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
guard let controller = try? SignInController(config: config) else { | |
logger.error("Could not initialize Controller") | |
return | |
} | |
controller.start() { [weak self] result in | |
guard let self = self else { return } | |
switch result { | |
case .failure(let error): |
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
public protocol ResourceConfigurable { | |
// The public PEM key converted to a JWK. | |
var jwk: JWK_RSA { get } | |
var privateKey: String { get } | |
var clientId: String { get } | |
var clientSecret: String { get } | |
// The "base URL" to use to make requests to the users Solid Pod. |
OlderNewer