diff --git a/src/Adapters/Auth/steam.js b/src/Adapters/Auth/steam.js index bf4f3e61..caefcff8 100644 --- a/src/Adapters/Auth/steam.js +++ b/src/Adapters/Auth/steam.js @@ -1,39 +1,46 @@ +/** + * Parse Server authentication adapter for Steam. + * + * @class SteamAdapter + * @param {Object} options - The adapter configuration options. + * + * @description + * ## Parse Server Configuration + * To configure Parse Server for Steam authentication, use the following structure: + * ```json + * { + * "auth": { + * "steam": { + * "appId": "your-app-id", + * "webApiKey": "your-web-api-key" + * } + * } + * } + * ``` + * + * The adapter requires the following `authData` fields: + * + * ## Auth Payloads + * ```json + * { + * "steam": { + * "??": "??" + * } + * } + * ``` + * + * @see {@link https://partner.steamgames.com/doc/api/ISteamUser#GetAuthTicketForWebApi Steam Web API docs} + */ + var Parse = require('parse/node').Parse; -const AppTicket = require('steam-appticket'); const https = require('https'); const querystring = require('querystring'); // Returns a promise that fulfills iff this application ticket is valid function validateAuthData(authData, authOptions) { - // using an encrypted app ticket to authenticate - if ("app_ticket" in authData) { - console.log("Authenticate steam user using encrypted app ticket"); - var encrypted_ticket = Buffer.from(authData.app_ticket, 'hex'); - var ticket = AppTicket.parseEncryptedAppTicket(encrypted_ticket, authOptions.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 (authOptions.appId !== ticket.appID && authOptions.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(); - } - // using the web api to authenticate - else if ("auth_ticket" in authData) { - console.log("Authenticate steam user using web api and auth ticket"); + if ("auth_ticket" in authData) { + //console.log("Authenticate steam user using web api and auth ticket"); return callSteamWebApi(authData.auth_ticket, authOptions); } @@ -66,12 +73,12 @@ function callSteamWebApi(auth_ticket, authOptions) { } var request = https.request(options, (response) => { - console.log("Steam web auth sucess"); + //console.log("Steam web auth sucess"); resolve(); }); request.on('error', (error) => { - console.log(error.message); + //console.log(error.message); reject('The Steam web api could not authenticate the user with the given auth ticket'); });