Skip to content

Commit

Permalink
Only attempt to refresh auth token when user is authenticated (#3721)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414709148257752/1208966018277167/f

**Description**:
Following [Increase of 401s in auth api -
Darwin](https://app.asana.com/0/0/1208959507432558) we found that the
refreshAuthTokenIfNeeded is being called without a proper check if user
is authenticated (and tokens are present).

It also includes BSK check ->
duckduckgo/BrowserServicesKit@fb809ed

**Steps to test this PR**:
1. Ensure no PP is on the device
2. Open PP purchase page
3. Check if `refreshAuthTokenIfNeeded` was not called and no calls to
`validate_token` endpoint were made.
4. Purchase or activate subscription
5. Open add/edit email page
6. Check if `refreshAuthTokenIfNeeded` was properly called with a call
to `validate_token` endpoint.

**Definition of Done (Internal Only)**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

**Copy Testing**:

* [ ] Use of correct apostrophes in new copy, ie `’` rather than `'`

**Orientation Testing**:

* [ ] Portrait
* [ ] Landscape

**Device Testing**:

* [ ] iPhone SE (1st Gen)
* [ ] iPhone 8
* [ ] iPhone X
* [ ] iPhone 14 Pro
* [ ] iPad

**OS Testing**:

* [ ] iOS 15
* [ ] iOS 16
* [ ] iOS 17

**Theme Testing**:

* [ ] Light theme
* [ ] Dark theme

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
miasma13 authored Dec 12, 2024
1 parent d70d5cd commit 02a9657
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11723,7 +11723,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 221.0.0;
version = "221.0.0-1";
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "9975e63265e617ce9c25ae1be6d531f6de5e6592",
"version" : "221.0.0"
"revision" : "276754fc1efab85c39a77da64e68439e7f105de3",
"version" : "221.0.0-1"
}
},
{
Expand Down Expand Up @@ -138,7 +138,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec
// MARK: Broker Methods (Called from WebView via UserScripts)

func getSubscription(params: Any, original: WKScriptMessage) async -> Encodable? {
await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded()
let authToken = accountManager.authToken ?? Constants.empty
guard accountManager.isUserAuthenticated else { return [Constants.token: Constants.empty] }

return [Constants.token: authToken]
switch await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded() {
case .success(let currentAuthToken):
return [Constants.token: currentAuthToken]
case .failure:
return [Constants.token: Constants.empty]
}
}

func getSubscriptionOptions(params: Any, original: WKScriptMessage) async -> Encodable? {
Expand Down

0 comments on commit 02a9657

Please sign in to comment.