Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription oauth v2 #1033

Draft
wants to merge 73 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
52c4e2f
Networking V2 implemented and tested
federicocappelli Sep 6, 2024
6deb71d
networking v2 refinements and unit tests
federicocappelli Sep 9, 2024
aecc91b
headers renamed
federicocappelli Sep 9, 2024
23800c2
mocks, lint
federicocappelli Sep 10, 2024
d029027
api configuration removed and data moved to api request, lint
federicocappelli Sep 10, 2024
ef4949c
query items changed and tests fixed
federicocappelli Sep 10, 2024
0dbc46e
added unit test
federicocappelli Sep 10, 2024
00bc2b2
Merge branch 'main' into fcappelli/networkingV2
federicocappelli Sep 10, 2024
0000972
privacy ref repo updated
federicocappelli Sep 10, 2024
309770b
pkg updated
federicocappelli Sep 10, 2024
d502223
comments
federicocappelli Sep 10, 2024
0ea4332
Documentation + comments and improvements
federicocappelli Sep 11, 2024
3101949
Doc
federicocappelli Sep 11, 2024
b20199d
Merge branch 'main' into fcappelli/networkingV2
federicocappelli Sep 11, 2024
a11b58b
v1 restore
federicocappelli Sep 11, 2024
46a7423
v1 restore
federicocappelli Sep 11, 2024
a7e2cae
tests fix
federicocappelli Sep 11, 2024
99f80f7
comment fix
federicocappelli Sep 11, 2024
d3ca645
auth client, service etc
federicocappelli Sep 11, 2024
193792f
authorise call + real tests
federicocappelli Sep 12, 2024
969514d
authorisation API done
federicocappelli Sep 13, 2024
bb8fb82
error handling fixed
federicocappelli Sep 13, 2024
6ea42ad
sendotp call
federicocappelli Sep 13, 2024
237c90e
renaming
federicocappelli Sep 16, 2024
ea3d225
Merge branch 'fcappelli/networkingV2' into fcappelli/subscription_oau…
federicocappelli Sep 16, 2024
48091f9
login api call
federicocappelli Sep 16, 2024
8c70535
more APIs
federicocappelli Sep 17, 2024
0b246d0
access token api requests
federicocappelli Sep 17, 2024
aa00362
optimisations
federicocappelli Sep 17, 2024
420f488
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Sep 18, 2024
1567199
JWT and JWKs
federicocappelli Sep 18, 2024
d7e7be2
new jwtpayload
federicocappelli Sep 19, 2024
552b281
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Sep 19, 2024
420be21
files ranamed
federicocappelli Sep 23, 2024
4b60204
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Sep 23, 2024
2d2425f
more oauthclient features
federicocappelli Sep 24, 2024
8bd8835
more account activation and editing
federicocappelli Sep 24, 2024
5b17d89
backup
federicocappelli Sep 27, 2024
8782e77
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 14, 2024
a300bb6
builds
federicocappelli Oct 16, 2024
3bc981d
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 16, 2024
18b64e4
auth and first purchase improved
federicocappelli Oct 21, 2024
0bbb394
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 21, 2024
085e85c
purchase flow fixed
federicocappelli Oct 22, 2024
9400b0c
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 22, 2024
aa8a036
api call param fix
federicocappelli Oct 23, 2024
2e2ada3
purchase fixed
federicocappelli Oct 23, 2024
1aac90f
loggers improved and restore fixed
federicocappelli Oct 24, 2024
69bcced
subscription refresh improved
federicocappelli Oct 25, 2024
3503e04
v1 to v2 auth migration
federicocappelli Oct 25, 2024
b778df6
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 25, 2024
b3873ea
lint
federicocappelli Oct 25, 2024
ec3409a
unit tests improvements
federicocappelli Oct 28, 2024
52ad921
review suggestions applied
federicocappelli Oct 29, 2024
6412ff9
more tests and logs
federicocappelli Oct 30, 2024
196b83e
vpn fixed
federicocappelli Oct 31, 2024
20e63ac
unit tests
federicocappelli Nov 1, 2024
095e7e1
signout as async
federicocappelli Nov 1, 2024
156814d
Merge branch 'main' of https://github.com/duckduckgo/BrowserServicesK…
federicocappelli Nov 4, 2024
e69f756
purchase fixes
federicocappelli Nov 4, 2024
f4e03fd
unit tests fixed + utilities
federicocappelli Nov 4, 2024
bbd9dac
unit tests
federicocappelli Nov 4, 2024
3b05a78
unit tests
federicocappelli Nov 4, 2024
edfdfbb
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 4, 2024
54182e2
subscripti token background refresh added
federicocappelli Nov 5, 2024
976f625
lint + tests
federicocappelli Nov 5, 2024
4bdca2a
lint
federicocappelli Nov 5, 2024
133b245
warnings and concurrency issue fixed
federicocappelli Nov 5, 2024
7a1edcc
tests fix
federicocappelli Nov 5, 2024
3161a3f
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 6, 2024
b01c07d
lint
federicocappelli Nov 6, 2024
92a2154
build import fixed
federicocappelli Nov 6, 2024
da30fc9
cleanup and errors improvements
federicocappelli Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
<key>FILEHEADER</key>
<string>
// ___FILENAME___
// DuckDuckGo
//
// Copyright © ___YEAR___ DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
20 changes: 10 additions & 10 deletions .swiftpm/xcode/xcshareddata/xcschemes/BrowserServicesKit.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -165,15 +165,15 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PhishingDetectionTests"
BuildableName = "PhishingDetectionTests"
BlueprintName = "PhishingDetectionTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PhishingDetectionTests"
BuildableName = "PhishingDetectionTests"
BlueprintName = "PhishingDetectionTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
67 changes: 67 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Networking.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Networking"
BuildableName = "Networking"
BlueprintName = "Networking"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Networking"
BuildableName = "Networking"
BlueprintName = "Networking"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
54 changes: 54 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/NetworkingTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NetworkingTests"
BuildableName = "NetworkingTests"
BlueprintName = "NetworkingTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
"version" : "6.0.1"
}
},
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "c2595b9ad7f512d7f334830b4df1fed6e917946a",
"version" : "4.13.4"
}
},
{
"identity" : "privacy-dashboard",
"kind" : "remoteSourceControl",
Expand All @@ -63,6 +72,15 @@
"version" : "3.0.0"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "81bee98e706aee68d39ed5996db069ef2b313d62",
"version" : "3.7.1"
}
},
{
"identity" : "swifter",
"kind" : "remoteSourceControl",
Expand Down
17 changes: 12 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ let package = Package(
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.29.0"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
.package(url: "https://github.com/1024jp/GzipSwift.git", exact: "6.0.1")
.package(url: "https://github.com/1024jp/GzipSwift.git", exact: "6.0.1"),
.package(url: "https://github.com/vapor/jwt-kit.git", exact: "4.13.4")
],
targets: [
.target(
Expand All @@ -70,7 +71,8 @@ let package = Package(
"UserScript",
"ContentBlocking",
"SecureStorage",
"Subscription"
"Subscription",
"Networking"
],
resources: [
.process("ContentBlocking/UserScripts/contentblockerrules.js"),
Expand Down Expand Up @@ -268,7 +270,8 @@ let package = Package(
.target(
name: "Networking",
dependencies: [
"Common",
.product(name: "JWTKit", package: "jwt-kit"),
"Common"
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down Expand Up @@ -356,7 +359,8 @@ let package = Package(
.target(
name: "Subscription",
dependencies: [
"Common"
"Common",
"Networking"
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand All @@ -365,7 +369,9 @@ let package = Package(
.target(
name: "SubscriptionTestingUtilities",
dependencies: [
"Subscription"
"Subscription",
"Common",
"TestUtils"
]
),
.target(
Expand Down Expand Up @@ -612,6 +618,7 @@ let package = Package(
dependencies: [
"Subscription",
"SubscriptionTestingUtilities",
"TestUtils",
]
),
.testTarget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ extension AutofillUserScript {

// https://github.com/duckduckgo/duckduckgo-autofill/blob/main/docs/runtime.ios.md#getautofilldatarequest
func getAutofillData(_ message: UserScriptMessage, _ replyHandler: @escaping MessageReplyHandler) {
guard let request: GetAutofillDataRequest = DecodableHelper.decode(from: message.messageBody) else {
guard let request: GetAutofillDataRequest = CodableHelper.decode(from: message.messageBody) else {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public let AutofillSecureVaultFactory: AutofillVaultFactory = SecureVaultFactory
///
/// * L0 - not encrypted. Currently no data at this level and we're not likely to use it.
/// * L1 - secret key encrypted. Usernames, domains, duck addresses.
/// * L2 - user password encrypted and can be accessed without password during a specifed amount of time. User passwords.
/// * L2 - user password encrypted and can be accessed without password during a specified amount of time. User passwords.
/// * L3 - user password is required at time of request. Currently no data at this level, but later e.g, credit cards.
///
/// Data always goes in and comes out unencrypted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public actor HTTPSUpgrade {
}

nonisolated public func loadDataAsync() {
logger.debug("loadDataAsync")
Task {
await self.loadData()
}
Expand Down
53 changes: 53 additions & 0 deletions Sources/Common/CodableHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// CodableHelper.swift
//
// Copyright © 2021 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import os.log

public struct CodableHelper {

public static func decode<Input: Any, T: Decodable>(from input: Input) -> T? {
do {
let json = try JSONSerialization.data(withJSONObject: input)
return try JSONDecoder().decode(T.self, from: json)
} catch {
Logger.general.error("Error decoding input: \(error.localizedDescription, privacy: .public)")
return nil
}
}

public static func decode<T: Decodable>(jsonData: Data) -> T? {
do {
return try JSONDecoder().decode(T.self, from: jsonData)
} catch {
Logger.general.error("Error decoding input: \(error.localizedDescription, privacy: .public)")
}
return nil
}

public static func encode<T: Codable>(_ object: T) -> Data? {
do {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
return try encoder.encode(object)
} catch let error {
Logger.general.error("Error encoding input: \(error.localizedDescription, privacy: .public)")
}
return nil
}
}
Loading
Loading