Skip to content

Commit 2b0efcb

Browse files
Bugfix FXIOS-14400 [Relay] Fix OAuth scopes (#31202)
* [FXIOS-14400] Fix OAuth for relay * No need for function call * [FXIOS-14400] Addtl log
1 parent 2b6e017 commit 2b0efcb

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

MozillaRustComponents/Sources/MozillaRustComponentsWrapper/FxAClient/FxAccountOAuth.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public enum OAuthScope {
1111
public static let oldSync: String = "https://identity.mozilla.com/apps/oldsync"
1212
// Necessary to obtain a sessionToken, which gives full access to the account.
1313
public static let session: String = "https://identity.mozilla.com/tokens/session"
14+
// Necessary for Relay email masking support.
15+
public static let relay: String = "https://identity.mozilla.com/apps/relay"
1416
}

firefox-ios/Client/Frontend/Browser/RelayController.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ final class RelayController: RelayControllerProtocol, Notifiable {
8282
}
8383
}
8484

85-
var scope: String {
86-
"profile"
87-
}
85+
var scope: String { OAuthScope.relay }
8886
}
8987

9088
// MARK: - Properties
@@ -136,7 +134,9 @@ final class RelayController: RelayControllerProtocol, Notifiable {
136134

137135
func emailFocusShouldDisplayRelayPrompt(url: URL) -> Bool {
138136
// Note: the prefs key defaults to On. No value (nil) should be treated as true.
139-
guard Self.isFeatureEnabled, profile.prefs.boolForKey(PrefsKeys.ShowRelayMaskSuggestions) ?? true else {
137+
guard Self.isFeatureEnabled,
138+
profile.prefs.boolForKey(PrefsKeys.ShowRelayMaskSuggestions) ?? true,
139+
client != nil else {
140140
return false
141141
}
142142
guard let relayRSClient, hasRelayAccount() else { return false }
@@ -157,7 +157,12 @@ final class RelayController: RelayControllerProtocol, Notifiable {
157157
return
158158
}
159159

160-
guard let webView = tab.webView, let client else { return }
160+
guard let webView = tab.webView, let client else {
161+
logger.log("No tab webview available, or client is nil. Will not populate email field.",
162+
level: .warning,
163+
category: .relay)
164+
return
165+
}
161166
Task {
162167
let (email, result) = await generateRelayMask(for: tab.url?.baseDomain ?? "", client: client)
163168
guard result != .error else { completion(.error); return }
@@ -319,7 +324,11 @@ final class RelayController: RelayControllerProtocol, Notifiable {
319324
switch result {
320325
case .success(let clients):
321326
let OAuthID = isStaging ? RelayOAuthClientID.stage.rawValue : RelayOAuthClientID.release.rawValue
322-
return clients.contains(where: { $0.clientId == OAuthID })
327+
let hasRelayID = clients.contains(where: { $0.clientId == OAuthID })
328+
if !hasRelayID {
329+
logger.log("No Relay service on this account.", level: .info, category: .relay)
330+
}
331+
return hasRelayID
323332
case .failure(let error):
324333
logger.log("Error fetching OAuth clients for Relay: \(error)", level: .warning, category: .relay)
325334
return false

firefox-ios/RustFxA/FirefoxAccountSignInViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class FirefoxAccountSignInViewController: UIViewController, Themeable {
313313
// We ask for the session scope because the web content never
314314
// got the session as the user never entered their email and
315315
// password
316-
scopes: [OAuthScope.profile, OAuthScope.oldSync, OAuthScope.session]
316+
scopes: [OAuthScope.profile, OAuthScope.oldSync, OAuthScope.session, OAuthScope.relay]
317317
) { [weak self] result in
318318
guard self != nil else { return }
319319

firefox-ios/RustFxA/FxAWebViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class FxAWebViewModel: FeatureFlaggable {
125125
case .emailLoginFlow:
126126
accountManager.beginAuthentication(
127127
entrypoint: "email_\(entrypoint)",
128-
scopes: [OAuthScope.profile, OAuthScope.oldSync]
128+
scopes: [OAuthScope.profile, OAuthScope.oldSync, OAuthScope.relay]
129129
) { [weak self] result in
130130
guard let self = self else { return }
131131

firefox-ios/RustFxA/RustFirefoxAccounts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public final class RustFirefoxAccounts: @unchecked Sendable {
186186
return FxAccountManager(
187187
config: config,
188188
deviceConfig: deviceConfig,
189-
applicationScopes: [OAuthScope.profile, OAuthScope.oldSync, OAuthScope.session],
189+
applicationScopes: [OAuthScope.profile, OAuthScope.oldSync, OAuthScope.session, OAuthScope.relay],
190190
keychainAccessGroup: accessGroupIdentifier,
191191
useRustKeychainForFxA: useRustKeychainForFxA
192192
)

0 commit comments

Comments
 (0)