Created
August 4, 2018 01:02
-
-
Save jerzzhang/fcdf2ecfe54920a7792517b98fb0e338 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
const momet = require('moment-timezone'); | |
const Requestor = require('../../requestor'); | |
const request = require('../../../lib/oemrequest_http'); | |
const adapter = 'ChryslerAdapter'; | |
const validator = joiValidate.create(adapter); | |
const requestor = { | |
name: { | |
adapter, | |
requestor: 'authenticate', | |
}, | |
validate: {}, | |
}; | |
requestor.request = function({credentials: {username, password}}) => ({ | |
type: 'http', | |
method: 'post', | |
url: 'https://vsb.cvp.extra.chrysler.com:8080/cvp-as/v1/tokens', | |
headers: { | |
'Content-Type': 'application/json', | |
'deviceid': '867979022113432', | |
'User-Agent': 'UAA', | |
}, | |
json: { | |
grant_type: 'password', | |
username, | |
password, | |
}, | |
}); | |
request.validate.error = function({response}) { | |
if (!response.access_token) { | |
throw new OemAuthenticationError(response); | |
} | |
} | |
requestor.validate.warn = function({response}) { | |
const schema = Joi.object().keys({ | |
accountDN: Joi.string().email(), | |
expires_in: Joi.string().regex(/^[0-9]+$/, 'numbers'), | |
token_type: Joi.string().regex(/^bearer$/), | |
refresh_token: Joi.string().guid(), | |
access_token: Joi.string().guid(), | |
authorization_token: Joi.string(), | |
}); | |
validator(response, schema); | |
}; | |
requestor.transform = function({response, credentials}) { | |
return { | |
auth: { | |
oemToken: response.access_token, | |
oemExpiration: moment().add(response.expires_in, 'seconds'), | |
oemUsername: credentials.username, | |
oemPassword: credentials.password, | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment