Remove broken app ticket code and add some docs (incomplete)
Some checks failed
ci / Code Analysis (javascript) (push) Has been cancelled
ci / Node Engine Check (push) Has been cancelled
ci / Lint (push) Has been cancelled
ci / Check Definitions (push) Has been cancelled
ci / Circular Dependencies (push) Has been cancelled
ci / Docker Build (push) Has been cancelled
ci / NPM Lock File Version (push) Has been cancelled
ci / Check Types (push) Has been cancelled
ci / MongoDB 7, ReplicaSet (push) Has been cancelled
ci / MongoDB 8, ReplicaSet (push) Has been cancelled
ci / Node 20 (push) Has been cancelled
ci / Node 22 (push) Has been cancelled
ci / Redis Cache (push) Has been cancelled
ci / PostgreSQL 16, PostGIS 3.5 (push) Has been cancelled
ci / PostgreSQL 17, PostGIS 3.5 (push) Has been cancelled
ci / PostgreSQL 18, PostGIS 3.6 (push) Has been cancelled
release-automated / release (push) Has been cancelled
release-automated / docker (push) Has been cancelled
release-automated / docs (push) Has been cancelled
Some checks failed
ci / Code Analysis (javascript) (push) Has been cancelled
ci / Node Engine Check (push) Has been cancelled
ci / Lint (push) Has been cancelled
ci / Check Definitions (push) Has been cancelled
ci / Circular Dependencies (push) Has been cancelled
ci / Docker Build (push) Has been cancelled
ci / NPM Lock File Version (push) Has been cancelled
ci / Check Types (push) Has been cancelled
ci / MongoDB 7, ReplicaSet (push) Has been cancelled
ci / MongoDB 8, ReplicaSet (push) Has been cancelled
ci / Node 20 (push) Has been cancelled
ci / Node 22 (push) Has been cancelled
ci / Redis Cache (push) Has been cancelled
ci / PostgreSQL 16, PostGIS 3.5 (push) Has been cancelled
ci / PostgreSQL 17, PostGIS 3.5 (push) Has been cancelled
ci / PostgreSQL 18, PostGIS 3.6 (push) Has been cancelled
release-automated / release (push) Has been cancelled
release-automated / docker (push) Has been cancelled
release-automated / docs (push) Has been cancelled
This commit is contained in:
@@ -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;
|
var Parse = require('parse/node').Parse;
|
||||||
const AppTicket = require('steam-appticket');
|
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const querystring = require('querystring');
|
const querystring = require('querystring');
|
||||||
|
|
||||||
|
|
||||||
// Returns a promise that fulfills iff this application ticket is valid
|
// Returns a promise that fulfills iff this application ticket is valid
|
||||||
function validateAuthData(authData, authOptions) {
|
function validateAuthData(authData, authOptions) {
|
||||||
// using an encrypted app ticket to authenticate
|
if ("auth_ticket" in authData) {
|
||||||
if ("app_ticket" in authData) {
|
//console.log("Authenticate steam user using web api and auth ticket");
|
||||||
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");
|
|
||||||
return callSteamWebApi(authData.auth_ticket, authOptions);
|
return callSteamWebApi(authData.auth_ticket, authOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +73,12 @@ function callSteamWebApi(auth_ticket, authOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var request = https.request(options, (response) => {
|
var request = https.request(options, (response) => {
|
||||||
console.log("Steam web auth sucess");
|
//console.log("Steam web auth sucess");
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
request.on('error', (error) => {
|
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');
|
reject('The Steam web api could not authenticate the user with the given auth ticket');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user