-
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.
- Loading branch information
Showing
8 changed files
with
159 additions
and
134 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
62 changes: 62 additions & 0 deletions
62
packages/fxa-content-server/app/scripts/models/auth_brokers/pairing/mixins/supplicant.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,62 @@ | ||
/* 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/. */ | ||
|
||
import OAuthErrors from '../../../../lib/oauth-errors'; | ||
import PairingChannelClient from '../../../../lib/pairing-channel-client'; | ||
import SupplicantStateMachine from '../../../pairing/supplicant-state-machine'; | ||
import setRemoteMetaData from '../remote-metadata'; | ||
|
||
/** | ||
* Shared functions of the supplicant auth brokers | ||
*/ | ||
|
||
const SupplicantMixin = { | ||
init(options) { | ||
const { config, notifier, relier } = options; | ||
|
||
if (!config.pairingClients.includes(relier.get('clientId'))) { | ||
// only approved clients may pair | ||
throw OAuthErrors.toError('INVALID_PAIRING_CLIENT'); | ||
} | ||
|
||
const channelServerUri = config.pairingChannelServerUri; | ||
const { channelId, channelKey } = relier.toJSON(); | ||
if (channelId && channelKey && channelServerUri) { | ||
this.pairingChannelClient = new PairingChannelClient( | ||
{ | ||
channelId, | ||
channelKey, | ||
channelServerUri, | ||
}, | ||
{ | ||
importPairingChannel: options.importPairingChannel, | ||
notifier, | ||
} | ||
); | ||
|
||
this.suppStateMachine = new SupplicantStateMachine( | ||
{}, | ||
{ | ||
broker: this, | ||
notifier, | ||
pairingChannelClient: this.pairingChannelClient, | ||
relier, | ||
} | ||
); | ||
|
||
this.pairingChannelClient.open(); | ||
} else { | ||
throw new Error('Failed to initialize supplicant'); | ||
} | ||
}, | ||
afterSupplicantApprove() { | ||
return Promise.resolve().then(() => { | ||
this.notifier.trigger('pair:supp:authorize'); | ||
}); | ||
}, | ||
|
||
setRemoteMetaData: setRemoteMetaData, | ||
}; | ||
|
||
export default SupplicantMixin; |
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
Oops, something went wrong.