-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oauth): support Fenix WebChannels
Ref: mozilla-mobile/android-components#3881 Fixes mozilla/application-services#1594 more tests wip
- Loading branch information
Showing
27 changed files
with
814 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/fxa-content-server/app/scripts/models/auth_brokers/oauth-webchannel-v1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* WebChannel OAuth broker that speaks 'v1' of the protocol. | ||
*/ | ||
import _ from 'underscore'; | ||
import ChannelMixin from './mixins/channel'; | ||
import Cocktail from 'cocktail'; | ||
import Constants from '../../lib/constants'; | ||
import HaltBehavior from '../../views/behaviors/halt'; | ||
import OAuthRedirectAuthenticationBroker from './oauth-redirect'; | ||
import ScopedKeys from 'lib/crypto/scoped-keys'; | ||
import WebChannel from '../../lib/channels/web'; | ||
import SyncEngines from '../sync-engines'; | ||
|
||
const proto = OAuthRedirectAuthenticationBroker.prototype; | ||
|
||
const OAuthWebChannelBroker = OAuthRedirectAuthenticationBroker.extend({ | ||
defaultBehaviors: _.extend({}, proto.defaultBehaviors, { | ||
afterForceAuth: new HaltBehavior(), | ||
afterSignIn: new HaltBehavior(), | ||
}), | ||
|
||
defaultCapabilities: _.extend({}, proto.defaultCapabilities, { | ||
chooseWhatToSyncWebV1: true, | ||
fxaStatus: true, | ||
openWebmailButtonVisible: false, | ||
}), | ||
|
||
commands: _.pick(WebChannel, 'FXA_STATUS', 'OAUTH_LOGIN'), | ||
|
||
type: 'oauth-webchannel-v1', | ||
|
||
initialize(options = {}) { | ||
this.session = options.session; | ||
this._channel = options.channel; | ||
this._scopedKeys = ScopedKeys; | ||
this._metrics = options.metrics; | ||
|
||
proto.initialize.call(this, options); | ||
this.request(this.getCommand('FXA_STATUS'), { | ||
service: this.relier.get('service'), | ||
}).then(response => this.onFxaStatus(response)); | ||
}, | ||
|
||
/** | ||
* Handle a response to the `fxa_status` message. | ||
* | ||
* @param {any} [response={}] | ||
* @private | ||
*/ | ||
onFxaStatus(response = {}) { | ||
const supportedEngines = | ||
response.capabilities && response.capabilities.engines; | ||
if (supportedEngines) { | ||
// supportedEngines override the defaults | ||
const syncEngines = new SyncEngines(null, { | ||
engines: supportedEngines, | ||
window: this.window, | ||
}); | ||
return this.set('chooseWhatToSyncWebV1Engines', syncEngines); | ||
} | ||
}, | ||
|
||
createChannel() { | ||
const channel = new WebChannel(Constants.ACCOUNT_UPDATES_WEBCHANNEL_ID); | ||
channel.initialize({ | ||
window: this.window, | ||
}); | ||
|
||
return channel; | ||
}, | ||
|
||
DELAY_BROKER_RESPONSE_MS: 100, | ||
|
||
sendOAuthResultToRelier(result, account) { | ||
result.redirect = Constants.OAUTH_WEBCHANNEL_REDIRECT; | ||
if (account && account.get('declinedSyncEngines')) { | ||
result.declinedSyncEngines = account.get('declinedSyncEngines'); | ||
result.offeredSyncEngines = account.get('offeredSyncEngines'); | ||
} | ||
|
||
return this.send(this.getCommand('OAUTH_LOGIN'), result); | ||
}, | ||
}); | ||
|
||
Cocktail.mixin(OAuthWebChannelBroker, ChannelMixin); | ||
|
||
export default OAuthWebChannelBroker; |
Oops, something went wrong.