Skip to content

Instantly share code, notes, and snippets.

View thomsmed's full-sized avatar
:octocat:
✌️😎

Thomas Asheim Smedmann thomsmed

:octocat:
✌️😎
View GitHub Profile
@thomsmed
thomsmed / printUserDefaultsKeys.swift
Created December 30, 2021 10:40
Print all available UserDefaults keys (iOS, iPadOS, macOS, watchOS, tvOS)
//
// printUserDefaultsKeys.swift
//
import Foundation
fileprivate let appGroupIdentifier = "group.com.my.app"
func printUserDefaultsKeys() {
print("Keys in standard UserDefaults:")
@thomsmed
thomsmed / AuthStateRepository.swift
Created December 31, 2021 16:44
AuthStateRepository.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// AuthStateRepository.swift
//
import Foundation
import AppAuth
protocol AuthStateRepository: AnyObject {
var state: OIDAuthState? { get }
func persist(state: OIDAuthState) throws
@thomsmed
thomsmed / KeychainAuthStateRepository.swift
Last active January 6, 2022 05:12
KeychainAuthStateRepository.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// KeychainAuthStateRepository.swift
//
import Foundation
import Security
import AppAuth
/**
Using the keychain to manage user secrets:
@thomsmed
thomsmed / SharedUserDefaultsAuthStateRepository.swift
Last active December 31, 2021 16:47
SharedUserDefaultsAuthStateRepository.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// SharedUserDefaultsAuthStateRepository.swift
//
import Foundation
import AppAuth
/**
Sharing access to keychain items among a collection of apps:
https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps
@thomsmed
thomsmed / AuthService.swift
Last active December 31, 2021 16:54
AuthService.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// AuthService.swift
//
import Foundation
enum AuthError: Error {
case missingConfiguration
case notAuthenticated
case failedToPersistState
@thomsmed
thomsmed / Auth0AuthService.swift
Last active December 31, 2021 16:55
Auth0AuthService.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Auth0AuthService.swift
//
import Foundation
import AppAuth
struct Auth0Configuration {
let openIdDomain: String
let openIdClientId: String
@thomsmed
thomsmed / AuthTokenProvider.swift
Created December 31, 2021 16:56
AuthTokenProvider.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// AuthTokenProvider.swift
//
import Foundation
protocol AuthTokenProvider: AnyObject {
func performWithFreshToken(_ action: @escaping (Result<String, Error>) -> Void)
}
@thomsmed
thomsmed / Auth0AuthService+AuthTokenProvider.swift
Last active June 28, 2022 08:35
Auth0AuthService+AuthTokenProvider.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Auth0AuthService+AuthTokenProvider.swift
//
import Foundation
import AppAuth
extension Auth0AuthService: AuthTokenProvider {
func performWithFreshToken(_ action: @escaping (Result<String, Error>) -> Void) {
guard let authState = authStateRepository.state else {
@thomsmed
thomsmed / WidgetAuthTokenProvider.swift
Created December 31, 2021 16:59
WidgetAuthTokenProvider.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// WidgetAuthTokenProvider.swift
//
import Foundation
final class WidgetAuthTokenProvider: AuthTokenProvider {
private let authStateRepository: AuthStateRepository
init(authStateRepository: AuthStateRepository) {
@thomsmed
thomsmed / ViewController.swift
Created January 1, 2022 22:42
ViewController.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// ViewController.swift
//
import UIKit
import TinyConstraints
enum TextType {
case info
case error