Skip to content

Commit 41eac13

Browse files
authored
Fix #5006 - Add ability to set custom identity.sync.tokenserver.uri for self-hosted Sync (#5158)
* Fix #5006 - Add ability to set custom identity.sync.tokenserver.uri for self-hosted Sync * Cleaned up a bunch of configuration stuff.
1 parent f24f2e1 commit 41eac13

21 files changed

+618
-454
lines changed

Account/FirefoxAccount.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,19 @@ open class FirefoxAccount {
164164
return dict
165165
}
166166

167-
open class func fromDictionary(_ dictionary: [String: Any]) -> FirefoxAccount? {
167+
open class func fromDictionary(_ dictionary: [String: Any], withPrefs prefs: Prefs) -> FirefoxAccount? {
168168
if let version = dictionary["version"] as? Int {
169169
// As of this writing, the current version, v2, is backward compatible with v1. The only
170170
// field added is pushRegistration, which is ok to be nil. If it is nil, then the app
171171
// will attempt registration when it starts up.
172172
if version <= AccountSchemaVersion {
173-
return FirefoxAccount.fromDictionaryV1(dictionary)
173+
return FirefoxAccount.fromDictionaryV1(dictionary, withPrefs: prefs)
174174
}
175175
}
176176
return nil
177177
}
178178

179-
fileprivate class func fromDictionaryV1(_ dictionary: [String: Any]) -> FirefoxAccount? {
179+
fileprivate class func fromDictionaryV1(_ dictionary: [String: Any], withPrefs prefs: Prefs) -> FirefoxAccount? {
180180
var configurationLabel: FirefoxAccountConfigurationLabel?
181181
if let rawValue = dictionary["configurationLabel"] as? String {
182182
configurationLabel = FirefoxAccountConfigurationLabel(rawValue: rawValue)
@@ -190,7 +190,7 @@ open class FirefoxAccount {
190190
let deviceName = dictionary["deviceName"] as? String ?? DeviceInfo.defaultClientName() // Upgrading clients may not have this key!
191191
let stateCache = KeychainCache.fromBranch("account.state", withLabel: dictionary["stateKeyLabel"] as? String, withDefault: SeparatedState(), factory: state)
192192
let account = FirefoxAccount(
193-
configuration: configurationLabel.toConfiguration(),
193+
configuration: configurationLabel.toConfiguration(prefs: prefs),
194194
email: email, uid: uid,
195195
deviceRegistration: deviceRegistration,
196196
declinedEngines: declinedEngines,
@@ -323,7 +323,7 @@ open class FirefoxAccount {
323323
self.fxaProfile = FxAProfile(email: email, displayName: displayName, avatar: avatarURL)
324324
}
325325

326-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
326+
let client = FxAClient10(configuration: configuration)
327327
client.getProfile(withSessionToken: married.sessionToken as NSData) >>== { result in
328328
self.fxaProfile = FxAProfile(email: result.email, displayName: result.displayName, avatar: result.avatarURL)
329329

@@ -342,7 +342,7 @@ open class FirefoxAccount {
342342
guard let married = stateCache.value as? MarriedState else {
343343
return deferMaybe(NotATokenStateError(state: stateCache.value))
344344
}
345-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
345+
let client = FxAClient10(configuration: configuration)
346346
return client.oauthAuthorize(withSessionToken: married.sessionToken as NSData, scope: FxAOAuthScope.OldSync).bind({ result in
347347
guard let oauthResponse = result.successValue else {
348348
return deferMaybe(ScopedKeyError())
@@ -366,7 +366,7 @@ open class FirefoxAccount {
366366
guard let session = stateCache.value as? TokenState else {
367367
return deferMaybe(NotATokenStateError(state: stateCache.value))
368368
}
369-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
369+
let client = FxAClient10(configuration: configuration)
370370
return client.devices(withSessionToken: session.sessionToken as NSData) >>== { resp in
371371
return remoteDevices.replaceRemoteDevices(resp.devices)
372372
}
@@ -388,7 +388,7 @@ open class FirefoxAccount {
388388
return deferMaybe(cachedOAuthKeyID)
389389
}
390390
// Otherwise, request the scoped key data from the server.
391-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
391+
let client = FxAClient10(configuration: configuration)
392392
return client.scopedKeyData(married.sessionToken as NSData, scope: scope).bind { response in
393393
guard let allScopedKeyData = response.successValue, let scopedKeyData = allScopedKeyData.find({ $0.scope == scope }), let kXCS = married.kXCS.hexDecodedData.base64urlSafeEncodedString else {
394394
return deferMaybe(ScopedKeyError())
@@ -414,7 +414,7 @@ open class FirefoxAccount {
414414
guard let session = stateCache.value as? TokenState else {
415415
return deferMaybe(NotATokenStateError(state: stateCache.value))
416416
}
417-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
417+
let client = FxAClient10(configuration: configuration)
418418
return client.notify(deviceIDs: deviceIDs, collectionsChanged: collections, reason: reason, withSessionToken: session.sessionToken as NSData) >>== { resp in
419419
guard resp.success else {
420420
return deferMaybe(NotifyError())
@@ -430,7 +430,7 @@ open class FirefoxAccount {
430430
guard let ownDeviceId = self.deviceRegistration?.id else {
431431
return deferMaybe(FxAClientError.local(NSError()))
432432
}
433-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
433+
let client = FxAClient10(configuration: configuration)
434434
return client.notifyAll(ownDeviceId: ownDeviceId, collectionsChanged: collections, reason: reason, withSessionToken: session.sessionToken as NSData) >>== { resp in
435435
guard resp.success else {
436436
return deferMaybe(NotifyError())
@@ -462,7 +462,7 @@ open class FirefoxAccount {
462462
KeychainStore.shared.setDictionary(nil, forKey: oauthResponseKeychainKey)
463463
}
464464

465-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
465+
let client = FxAClient10(configuration: configuration)
466466
return client.destroyDevice(ownDeviceId: ownDeviceId, withSessionToken: session.sessionToken as NSData) >>> succeed
467467
}
468468

@@ -504,7 +504,7 @@ open class FirefoxAccount {
504504
registration = succeed()
505505
}
506506
let deferred: Deferred<FxAState> = registration.bind { _ in
507-
let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
507+
let client = FxAClient10(configuration: self.configuration)
508508
let stateMachine = FxALoginStateMachine(client: client)
509509
let now = Date.now()
510510
return stateMachine.advance(fromState: cachedState, now: now).map { newState in

0 commit comments

Comments
 (0)