Skip to content

Commit

Permalink
Merge pull request geteduroam#17 from geteduroam/feature/GETEDUROAM-19
Browse files Browse the repository at this point in the history
GETEDUROAM-19: Use new EAP data model to configure, split up EAP to s…
  • Loading branch information
johankool authored Dec 16, 2022
2 parents 2f39234 + 82b71ff commit 7af7cf7
Show file tree
Hide file tree
Showing 28 changed files with 529 additions and 542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@
"version" : "0.9.1"
}
},
{
"identity" : "fuzi",
"kind" : "remoteSourceControl",
"location" : "https://github.com/cezheng/Fuzi",
"state" : {
"revision" : "f08c8323da21e985f3772610753bcfc652c2103f",
"version" : "3.1.3"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version" : "1.0.0"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -90,15 +72,6 @@
"version" : "0.5.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swift-parsing",
"kind" : "remoteSourceControl",
Expand Down
13 changes: 0 additions & 13 deletions ios/geteduroam/GeteduroamPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ let package = Package(
.library(
name: "DiscoveryClient",
targets: ["DiscoveryClient"]),
.library(
name: "EAPConfigParser",
targets: ["EAPConfigParser"]),
.library(
name: "Connect",
targets: ["Connect"]),
Expand All @@ -34,8 +31,6 @@ let package = Package(
targets: ["EAPConfigurator"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/cezheng/Fuzi", from: "3.0.0"),
.package(url: "https://github.com/openid/AppAuth-iOS.git", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "0.42.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
Expand Down Expand Up @@ -75,18 +70,10 @@ let package = Package(
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "URLRouting", package: "swift-url-routing")
]),
.target(
name: "EAPConfigParser",
dependencies: [
"Models",
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "Fuzi", package: "Fuzi")
]),
.target(
name: "Connect",
dependencies: [
"AuthClient",
"EAPConfigParser",
"EAPConfigurator",
"Models",
.product(name: "AppAuth", package: "AppAuth-iOS"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import AppAuth
import AuthClient
import ComposableArchitecture
import EAPConfigParser
import EAPConfigurator
import Foundation
import Models
import SwiftUI
import XMLCoder

public struct Connect: ReducerProtocol {
public let authClient: AuthClient
Expand Down Expand Up @@ -80,6 +80,7 @@ public struct Connect: ReducerProtocol {
case missingAuthorizationEndpoint
case missingTokenEndpoint
case accessPointConfigurationFailed
case noValidProviderFound
}

public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
Expand Down Expand Up @@ -129,6 +130,15 @@ public struct Connect: ReducerProtocol {
}
}

var decoder: XMLDecoder = {
let decoder = XMLDecoder()
decoder.shouldProcessNamespaces = true
decoder.dateDecodingStrategy = .iso8601
return decoder
}()

@Dependency(\.date) var date

func connect(profile: Profile, authClient: AuthClient) async throws {
let accessToken: String?
if profile.oauth ?? false {
Expand Down Expand Up @@ -166,9 +176,18 @@ public struct Connect: ReducerProtocol {

let (eapConfigData, _) = try await URLSession.shared.data(for: urlRequest)

let accessPoint = try EAPConfigParser.parse(xmlData: eapConfigData)
let providerList = try decoder.decode(EAPIdentityProviderList.self, from: eapConfigData)
let firstValidProvider = providerList
.providers
.first(where: { ($0.validUntil?.timeIntervalSince(date()) ?? 0) >= 0 })

guard let firstValidProvider else {
throw InstitutionSetupError.noValidProviderFound
}

try await EAPConfigurator().configure(identityProvider: firstValidProvider)

try await EAPConfigurator().configure(accessPoint: accessPoint)
// TODO: Check if connection works?
}

}

This file was deleted.

Loading

0 comments on commit 7af7cf7

Please sign in to comment.