in Modules/token-path.js [118:181]
function requestSetOfCodes(event, callback) {
// Generating the user code (a unique code to return to the end user) and device code (a unique code for future device calls)
var user_code = common.randomString(process.env.USER_CODE_LENGTH, process.env.USER_CODE_FORMAT);
var device_code = common.randomString(process.env.DEVICE_CODE_LENGTH, process.env.DEVICE_CODE_FORMAT);
var scope = 'openid';
// Creating a JSON structure to return codes to the device
var codes = {
device_code: device_code,
user_code: user_code,
verification_uri: "https://" + process.env.CODE_VERIFICATION_URI + "/device",
verification_uri_complete: "https://" + process.env.CODE_VERIFICATION_URI + "/device?code=" + user_code + "&authorize=true",
interval: parseInt(process.env.POLLING_INTERVAL),
expires_in: parseInt(process.env.CODE_EXPIRATION)
};
if (event.queryStringParameters.scope && event.queryStringParameters.scope != '' ) {
scope = event.queryStringParameters.scope;
} else {
scope = 'openid';
}
// Prepare the stroage of the codes in the DynamoDB table
var DynamoDBParams = {
Item: {
"Device_code": {
S: device_code
},
"User_code": {
S: user_code
},
"Status": {
S: "authorization_pending"
},
"Client_id": {
S: event.queryStringParameters.client_id
},
"Max_expiry": {
S: (Date.now() + process.env.CODE_EXPIRATION * 1000).toString()
},
"Last_checked": {
S: (Date.now()).toString()
},
"Scope": {
S: scope
}
},
ReturnConsumedCapacity: "TOTAL",
TableName: process.env.DYNAMODB_TABLE
};
// Insert the item in DynamoDB
common.dynamodb.putItem(DynamoDBParams, function(err, data) {
if (err) {
//There was an error
console.log(err, err.stack);
console.log("Error inserting Codes item in the DynamoDB table");
common.returnJSONError(500, callback);
} else {
//Successful, the Authorization request has been written to the DynamoDB table
console.log("Inserting Codes item in the DynamoDB table: " + data);
common.returnJSONSuccess(codes, callback);
}
});
}