Steam WebAPI 验证用户
Steam WebAPI AuthenticateUser
如何通过 https://api.steampowered.com/ISteamUserAuth/AuthenticateUser/v0001 api 方法授权用户?
例如,我将从https://steamcommunity.com/login/getrsakey/获取steam public密钥数据,进行一些加密,然后将此数据发送到指定的api url作为[=34] =].
但是服务器 returns 每次都是“403 Forbidden”。
我的代码示例:
from Crypto.Cipher import AES
from Crypto.Cipher.PKCS1_v1_5 import PKCS115_Cipher
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
import hashlib
import json
import requests
steamid = '<MY_STEAMID64>'
steampass = '<MY_STEAM_PASSWORD>'
loginkey = hashlib.md5(bytes(steampass, 'utf-8')).hexdigest()
blob32 = get_random_bytes(32)
getrsa_url = 'https://steamcommunity.com/login/getrsakey/'
getrsa_data = {'username': '<MY_STEAM_USERNAME>'}
getrsa_resp = requests.get(getrsa_url, params=getrsa_data)
response = json.loads(getrsa_resp.text)
if response.get('success'):
steam_publickey_mod = response.get('publickey_mod')
steam_publickey_mod = int(steam_publickey_mod, 16)
steam_publickey_exp = response.get('publickey_exp')
steam_publickey_exp = int(steam_publickey_exp, 16)
steam_rsa_key = RSA.construct((steam_publickey_mod, steam_publickey_exp))
steam_rsa = PKCS115_Cipher(steam_rsa_key)
if steam_rsa_key.can_encrypt():
sessionkey = steam_rsa.encrypt(blob32)
if type(sessionkey) is tuple:
sessionkey = sessionkey[0]
steam_aes = AES.new(blob32)
encrypted_loginkey = steam_aes.encrypt(loginkey)
if all([steamid, sessionkey, encrypted_loginkey]):
authenticate_user_url = (
'https://api.steampowered.com/ISteamUserAuth/AuthenticateUser/v0001')
authenticate_user_json = {
'steamid': steamid,
'sessionkey': sessionkey,
'encrypted_loginkey': encrypted_loginkey,
}
if __name__ == '__main__':
import ipdb
ipdb.set_trace()
authenticate_user_resp = requests.post(url=authenticate_user_url,
data=authenticate_user_json)
authenticate_user_resp.ok returns 错
authenticate_user_resp.status_code returns 403
authenticate_user_resp.reason returns 禁止
对不起,我的英语不好,请
据我所知,您不能执行此操作,因此“403 禁止”因此,您根本无法 "authorized" 使用您拥有的凭据执行此操作。
https://en.wikipedia.org/wiki/HTTP_403
A 403 response generally indicates one of two conditions:
Authentication was provided, but the authenticated user is not
permitted to perform the requested operation. The operation is
forbidden to all users. For example, requests for a directory listing
return code 403 when directory listing has been disabled.
AuthenticateUser 并不像您想象的那样。 Steam 客户端使用它为当前登录客户端的用户获取网络会话登录 cookie。 AuthenticateUser请求的loginkey来自CM(客户端连接的服务器)
如果您想让用户登录网站,您需要使用 HTTP 端点来执行此操作。获得 RSA 密钥并使用该密钥加密密码后,您可以通过在正文中使用以下 urlencoded 参数发布到 https://steamcommunity.com/login/dologin/ 来进行身份验证:
captcha_text
- 空字符串或系统提示的验证码文本
captchagid
- 已提示您使用的验证码的 GID,如果未提示,则为 -1
emailauth
- 发送到您的电子邮件地址的 Steam 令牌代码,如果不适用则为空字符串
emailsteamid
- 空字符串
loginfriendlyname
- 空字符串
password
- 您的密码,使用 RSA public 密钥加密,生成的 base64 密文
remember_login
- true
如果你想记住你的登录或 false
如果不是(字符串 true
和 false
)
rsatimestamp
- 使用 RSA 密钥获得的时间戳
twofactorcode
- 您从移动应用程序获得的 TOTP 代码,如果不适用则为空字符串
username
- 您的账户名
如何通过 https://api.steampowered.com/ISteamUserAuth/AuthenticateUser/v0001 api 方法授权用户?
例如,我将从https://steamcommunity.com/login/getrsakey/获取steam public密钥数据,进行一些加密,然后将此数据发送到指定的api url作为[=34] =]. 但是服务器 returns 每次都是“403 Forbidden”。
我的代码示例:
from Crypto.Cipher import AES
from Crypto.Cipher.PKCS1_v1_5 import PKCS115_Cipher
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
import hashlib
import json
import requests
steamid = '<MY_STEAMID64>'
steampass = '<MY_STEAM_PASSWORD>'
loginkey = hashlib.md5(bytes(steampass, 'utf-8')).hexdigest()
blob32 = get_random_bytes(32)
getrsa_url = 'https://steamcommunity.com/login/getrsakey/'
getrsa_data = {'username': '<MY_STEAM_USERNAME>'}
getrsa_resp = requests.get(getrsa_url, params=getrsa_data)
response = json.loads(getrsa_resp.text)
if response.get('success'):
steam_publickey_mod = response.get('publickey_mod')
steam_publickey_mod = int(steam_publickey_mod, 16)
steam_publickey_exp = response.get('publickey_exp')
steam_publickey_exp = int(steam_publickey_exp, 16)
steam_rsa_key = RSA.construct((steam_publickey_mod, steam_publickey_exp))
steam_rsa = PKCS115_Cipher(steam_rsa_key)
if steam_rsa_key.can_encrypt():
sessionkey = steam_rsa.encrypt(blob32)
if type(sessionkey) is tuple:
sessionkey = sessionkey[0]
steam_aes = AES.new(blob32)
encrypted_loginkey = steam_aes.encrypt(loginkey)
if all([steamid, sessionkey, encrypted_loginkey]):
authenticate_user_url = (
'https://api.steampowered.com/ISteamUserAuth/AuthenticateUser/v0001')
authenticate_user_json = {
'steamid': steamid,
'sessionkey': sessionkey,
'encrypted_loginkey': encrypted_loginkey,
}
if __name__ == '__main__':
import ipdb
ipdb.set_trace()
authenticate_user_resp = requests.post(url=authenticate_user_url,
data=authenticate_user_json)
authenticate_user_resp.ok returns 错
authenticate_user_resp.status_code returns 403
authenticate_user_resp.reason returns 禁止
对不起,我的英语不好,请
据我所知,您不能执行此操作,因此“403 禁止”因此,您根本无法 "authorized" 使用您拥有的凭据执行此操作。
https://en.wikipedia.org/wiki/HTTP_403
A 403 response generally indicates one of two conditions:
Authentication was provided, but the authenticated user is not permitted to perform the requested operation. The operation is forbidden to all users. For example, requests for a directory listing return code 403 when directory listing has been disabled.
AuthenticateUser 并不像您想象的那样。 Steam 客户端使用它为当前登录客户端的用户获取网络会话登录 cookie。 AuthenticateUser请求的loginkey来自CM(客户端连接的服务器)
如果您想让用户登录网站,您需要使用 HTTP 端点来执行此操作。获得 RSA 密钥并使用该密钥加密密码后,您可以通过在正文中使用以下 urlencoded 参数发布到 https://steamcommunity.com/login/dologin/ 来进行身份验证:
captcha_text
- 空字符串或系统提示的验证码文本captchagid
- 已提示您使用的验证码的 GID,如果未提示,则为 -1emailauth
- 发送到您的电子邮件地址的 Steam 令牌代码,如果不适用则为空字符串emailsteamid
- 空字符串loginfriendlyname
- 空字符串password
- 您的密码,使用 RSA public 密钥加密,生成的 base64 密文remember_login
-true
如果你想记住你的登录或false
如果不是(字符串true
和false
)rsatimestamp
- 使用 RSA 密钥获得的时间戳twofactorcode
- 您从移动应用程序获得的 TOTP 代码,如果不适用则为空字符串username
- 您的账户名