I am trying to log in to a website like for this example csgolounge which requires the steam login authentication using nodejs.
Even thought I have tried a few things none of them came even close to working, so there is no point of me including the code here.
I was wondering if there is any way of doing this.
EDIT: I think I write my question incorrectly as I want the node application to login to csgolounge using steam and NOT have a website that is 'like' csgolounge with the login option.
To answer your question, yes. There is a way of doing this.
The first thing you'll need to do is get a steam api key which you can do by heading over here. Then as steam says:
Just download an OpenID library for your language and platform of choice and use http://steamcommunity.com/openid as the provider. The returned Claimed ID will contain the user's 64-bit SteamID. The Claimed ID format is: http://steamcommunity.com/openid/id/
If you're set on using Node.JS I suggest checking out node-jsonwebtoken or passport-openidconnect. If you choose to go with passport, someone has already developed a "strategy" for including steam. Check that out here.
I have the same issue, i dont know if it helps you, but i wrote some methods to get user steamID, then u can use it to get user info with this method. I did it only having info how to do it with PHP - thats why i wanted to rewrite it on js.
1) method to build link
const http_build_query = (obj) => {
let str = ""
for (const key in obj) {
const value = obj[key];
str += `${key}=${value}&`;
}
return str;
}
2) method which returns you link where you shoud go to login with steam (you also can use in in )
const genUrl = (urlToReturnTo) => {
const params = {
'openid.ns' : 'http://specs.openid.net/auth/2.0',
'openid.mode' : 'checkid_setup',
'openid.return_to' : urlToReturnTo,
'openid.realm' : 'http://localhost:8080',
'openid.identity' : 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.claimed_id' : 'http://specs.openid.net/auth/2.0/identifier_select',
};
const url = `${STEAM_LOGIN}?${http_build_query(params)}`
return url;
};
Also in method genUrl you need to pass as a param url where you want to be redirected after login. If login is successful you will be redirected to your url and will have some params in url it will look like "http://yoururl?here_is_params"
and you need to get some how [here_is_params] from url i used this:
const search = location.search.substring(1);
const urlObj = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
So after that you will have an object with query params
3) Now all you need its to get steamID from this object:
const getUserId = (response) =>
{
const str = response["openid.claimed_id"];
const res = decodeURIComponent(str)
const propsArr = res.split("\/");
console.log(propsArr);
return propsArr[propsArr.length-1];
}
const userId = getUserId(urlObj)
4) Now you have userId and all you need its to send request with fetch or axios. it will return you an JSON OBJ with user data
http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={apiKey}&steamids=${userId}
Related
I need to pass the get api urls for fetch the data from one application to another application. I have temporary solution as the url details in queryParams and use it in another application. Is there any professional way to implement for build url with dynamically?
In my first application i have build the url as below
async buildUrl(applicationId, getUrl) {
let url = this.filterBaseurl + `datafilter/get-filter-utility?entityId=${applicationId}&connectorName=${this.connectorName}&entityName=${this.entityName}&getUrl=${getUrl}`
return url
}
example result of above function is
${baseUrl}/datafilter/get-filter-utility?entityId=12345678&connectorName=greenhouse&entityName=engagement-request&getUrl=jobs
in my another application i have calling the required api url
let queryparams = req.queryParams
let url = ${queryparams.getUrl}/{queryparams.entityId}
let response = await this.restProvider.get(url)
the way i have implement with queryParams is unprofessional, is there any better way to build the api url dynamically. one difficulty is i shouldn't call second application's api endpoint from first application.
Something like this?
var x1 = new URL("https://example.org")
x1.searchParams.append("x", "y")
Sorry, this is not a code question.
I'm currently working on a web application using React.
I've been using Redux to manage user registration information (ex: email address, etc.) for user registration over several pages, but I noticed that the registered information disappears after reloading.
I thought about saving the information to localStorage, but gave up due to the security risk.
How would you guys keep your users' registration information?
If the information is not much, you could use encrypted cookie data, and read back the data on page load.
Create a .env file in your project root folder
Save your pass access in this file like so REACT_APP_PASS=8604460484466
use a function like
const encryptWithAES = (text, pass) => {
const passphrase = pass;
return CryptoJS.AES.encrypt(text, passphrase).toString();
}; // remember to import CryptoJS
When the page loads you can read the data with:
export const decryptWithAES = (ciphertext, pass) => {
const passphrase = pass;
const bytes = CryptoJS.AES.decrypt(ciphertext, passphrase);
const originalText = bytes.toString(CryptoJS.enc.Utf8);
return originalText;
};
When you want to store the cookie, then you can do it like so:
const tobeStored = encryptWithAES('text to encrypt', process.env.REACT_APP_PASS);
// then store it in your cookie.
When you want to retrieve it:
const cookieData = someGetCookieFunction('UserInfo');
const decrypted = decryptWithAES(cookieData,process.env.REACT_APP_PASS);
I am assuming that you know how to read cookie from your script.
See more information here and Here As well on how to set and call environment variables.
I'm making a Discord bot in JavaScript and implementing a feature where when you ask a coding question it gives you a snippet. I'm using Grepper and returning the url with the search results. For example:
Hello World in JavaScript Search Results. I would like to access the div containing the snippet. Is this possible? And how would I do it?
Here's my code:
if (message.startsWith('programming')) {
// Command = programming
message = message.replace('programming ', ''); // Remove programming from the string
message = encodeURIComponent(message) // Encode the string for a url
msg.channel.send(`https://www.codegrepper.com/search.php?answer_removed=1&q=${message}`); // Place formatted string into url and send it to the discord server
// Here the program should access the element containing the snippet instead of sending the url:
}
I'm new to JavaScript so sorry if this is a stupid question.
As far as I know the API you are using returns HTML/Text data, not JSON, Grepper has a lot more APIs if you just look into them, you can instead use this API that returns JSON data. If you need more information you can check this Unofficial List of Grepper APIs
https://www.codegrepper.com/api/get_answers_1.php?v=2&s=${SearchQuery}&u=98467
How Do I Access the div containing the snippet?
To access the div you might need to use python web scraping to scrape the innerHTML of the div but I think it's easier to use the other API.
Or
You can put /api/ in the url like:
https://www.codegrepper.com/api/search.php?answer_removed=1&q=js%20loop
The easiest way for this is to send a GET request to the underlying API
https://www.codegrepper.com/api/search.php?q=hello%20world%20javascript&search_options=search_titles
This will return the answers in JSON format. Obviously you'd have to adjust the parameters.
How did I find out about this?
Simply look at the network tab of your browser's dev tools while loading the page. You'll see a GET request being sent out to the endpoint, returning mentioned answers as JSON.
The best way is to use the grepper api.
Install node-fetch
npm i node-fetch, You need this package for making requestes to the api.
To import It in the code just type:
const fetch = require('node-fetch');
Write this code
Modify your code like this:
if (message.startsWith('programming')) {
message = message.replace('programming ', '');
message = encodeURIComponent(message)
// Making the request
fetch(`https://www.codegrepper.com/api/search.php?answer_removed=1&q=${message}`)
.then(res => res.json())
.then(response => {
// response is a json object containing all the data You need
// now You need to parse this data
const answers = response.answers; // this is an array of objects
const answers_limit = 3; // set a limit for the answers
// cheking if there is any answer
if(answers.length == 0) {
return msg.channel.send("No answers were found!");
}
// creating the embed
const embed = new Discord.MessageEmbed()
.setTitle("Here the answers to your question!")
.setDescription("")
// parsing
for(let i = 0; i < answers_limit; i++) {
if(answers[i]) {
embed.description += `**${i+1}° answer**:\n\`\`\`js\n${answers[i].answer}\`\`\`\n`;
}
}
console.log(embed)
msg.channel.send(embed);
});
}
I've got a react component that allows users to unsubscribe from an email, and there's a hash being passed along with the unsubscribe link so we know what mail item the request is associated with. Unfortunately the hash sometimes has some URL-specific characters in it, like + and /. Right now I'm doing something like this to get the data from the hash to pass to the unsubscribe service:
const query = new URLSearchParams(useLocation().search);
const campaignId = query.get('campaign') ?? '';
the problem is that when I pass the campaign in to the unsubscribe, and (for example) the campaig hash has a + in it, that gets converted to a space.
Is there a better way to get this string, or a way to "un-encode" it?
I ended up doing something fairly inelegant-- but it works. I used the decodeURIComponent() as suggested by #ofri in the comments above, but the spaces were not being converted back to +. So this is what I came up with:
const query = new URLSearchParams(useLocation().search);
const campaignId = query.get('campaignId') ?? '';
// then when we create the axios payload:
campaignId : decodeURIComponent(campaignId.replace(/ /g, '+'))
I am on MobileFirst 7.1, and I am trying to do something similar to this: Get user id from inside a protected adapter but this time is in javascript.
I have followed the tutorial and the protected procedure triggers login, I have made sure that application-descriptor.xml contains <userIdentityRealms>MyRealm</userIdentityRealms> however user identity is null(again).
How can I get the user identity from inside the following procedure?
function myProcedure() {
// I want to get the userid this Java into Javascript,
// SecurityAPI security = serverAPI.getSecurityAPI();
// OAuthUserIdentity identity = security.getSecurityContext().getUserIdentity();
// String userid = identity.getId();
var userid = ???
var facade = new com.ibm.jp.facade.SomeFacade();
var list = facade.SomeMethod(userid);
return JSON.parse(list);
}
In the beginning I was trying to get the user identity from inside the Java facade but it is null. I suspect it is not in the same context? That is why I am trying to get it from the js adapter and pass it as a parameter of someMethod(). If there is a better way to get it I would like to know.
I found it!
var user = WL.Server.getActiveUser();
var userid = user.userId;
...