diff --git a/src/Adapters/Auth/index.js b/src/Adapters/Auth/index.js index 7f5581da..35b5661f 100755 --- a/src/Adapters/Auth/index.js +++ b/src/Adapters/Auth/index.js @@ -23,6 +23,7 @@ import oauth2 from './oauth2'; const phantauth = require('./phantauth'); import qq from './qq'; import spotify from './spotify'; +const steam = require("./steam"); import twitter from './twitter'; const vkontakte = require('./vkontakte'); import wechat from './wechat'; @@ -50,6 +51,7 @@ const providers = { google, github, twitter, + steam, spotify, anonymous, digits, diff --git a/src/Adapters/Auth/steam.js b/src/Adapters/Auth/steam.js new file mode 100644 index 00000000..3a299b69 --- /dev/null +++ b/src/Adapters/Auth/steam.js @@ -0,0 +1,36 @@ +var Parse = require('parse/node').Parse; +const AppTicket = require('steam-appticket'); + +// todo move these to a config file. +const decryptionKey = '3e3e2a3cbd54dc6c7cb5e51520dfa819dd7f9c12d062d54a1f8c14ddd231377f'; +const appId = '3414340'; + +// Returns a promise that fulfills iff this application ticket is valid +function validateAuthData(authData) { + var encrypted_ticket = Buffer.from(authData.app_ticket, 'hex'); + var ticket = AppTicket.parseEncryptedAppTicket(encrypted_ticket, decryptionKey) + if (ticket === null) { + throw new Parse.Error( + Parse.Error.OBJECT_NOT_FOUND, + 'Steam auth is invalid for this user.'); + } + var user_id = authData.id; + if (user_id != ticket.steamID.accountid) { + throw new Parse.Error( + Parse.Error.OBJECT_NOT_FOUND, + 'The provided application ticket does not match the given user id' + ); + } + if (appId !== ticket.appID && demoAppId != ticket.appID) { + throw new Parse.Error( + Parse.Error.OBJECT_NOT_FOUND, + 'The provided application ticket does not match the Kami 2 or Kami 2 Demo application ids' + ); + } + return Promise.resolve(); +} + +// steam auth bundles the app id in the auth data so don't validate seperately +function validateAppId() { + return Promise.resolve(); +} \ No newline at end of file