UNPKG

@hydrogenplatform/raindrop

Version:

Convenience functions to integrate Raindrop authentication into your project.

72 lines (60 loc) 1.74 kB
const common = require('./commonCalls') class RaindropPartner extends common.BasicPartner { constructor (config) { if (!config.applicationId) { throw new common.RaindropError('Please provide your applicationId in the config: {applicationId: ..., ...}') } let clientConfig = Object.assign({}, config) delete config.applicationId super(config) this.applicationId = clientConfig.applicationId } } RaindropPartner.prototype.registerUser = function (hydroID) { var options = { method: 'POST', body: { hydro_id: hydroID, application_id: this.applicationId } } return this.callHydroAPI('/application/client', options) } RaindropPartner.prototype.verifySignature = function (hydroID, challengeString) { var options = { method: 'GET', qs: { message: challengeString, hydro_id: hydroID, application_id: this.applicationId } } var receivedVerboseValue = this.verbose this.verbose = true return this.callHydroAPI('/verify_signature', options) .then(result => { this.verbose = receivedVerboseValue return { verified: true, data: result } }) .catch(error => { this.verbose = receivedVerboseValue if (error.statusCode === 401) { return { verified: false } } else { throw new common.RaindropError(`The call failed. ${error.statusCode} error: ${error.message}.`) } }) } RaindropPartner.prototype.unregisterUser = function (hydroID) { var options = { method: 'DELETE', qs: { hydro_id: hydroID, application_id: this.applicationId } } return this.callHydroAPI('/application/client', options) } module.exports = { RaindropPartner: RaindropPartner }