summaryrefslogtreecommitdiffstats
path: root/ios/Hæ-appen/Auth.swift
blob: 09da4af7b2877dfe1de14b27d815e14ee09b5066 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
//  Auth.swift
//  Hæ-appen
//
//  Created by Ivar Løvlie on 03/12/2025.
//
import SwiftUI
import AuthenticationServices
import OSLog

struct Auth {
    let logger = Logger(subsystem: "com.yourcompany.app", category: "auth")
    func login() -> Void {
        guard let url = URL(string:"http://192.168.0.103:5281/login") else {return}
        let session = ASWebAuthenticationSession(url: url, callbackURLScheme: "what") {
            callbackURL, error in
            guard error == nil, let callbackURL = callbackURL else { return }
            let queryItems = URLComponents(string: callbackURL.absoluteString)?.queryItems
            _ = queryItems?.filter({ $0.name == "code" }).first?.value
        }
        let vc = AuthViewController()
        session.presentationContextProvider = vc
        session.start()
        return
    }
    func register() -> Void {
        return
    }
    func logout() -> Void {
        return
    }
    
}

class AuthViewController: UIViewController, ASWebAuthenticationPresentationContextProviding
{
    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        return ASPresentationAnchor()
    }
}