Skip to content

Instantly share code, notes, and snippets.

@qwexvf
Created October 17, 2017 07:17
Show Gist options
  • Save qwexvf/26215f8d5ead61ba65af013dd00c75a5 to your computer and use it in GitHub Desktop.
Save qwexvf/26215f8d5ead61ba65af013dd00c75a5 to your computer and use it in GitHub Desktop.
Python Steam Login
from flask import Flask, redirect
from urllib import parse
import requests
import json
app = Flask(__name__)
@app.route('/')
def hello_world():
steam_openid_url = 'https://steamcommunity.com/openid/login'
u = {
'openid.ns': "http://specs.openid.net/auth/2.0",
'openid.identity': "http://specs.openid.net/auth/2.0/identifier_select",
'openid.claimed_id': "http://specs.openid.net/auth/2.0/identifier_select",
'openid.mode': 'checkid_setup',
'openid.return_to': 'http://192.168.33.10:8081/setup',
'openid.realm': 'http://192.168.33.10:8081'
}
query_string = parse.urlencode(u)
auth_url = steam_openid_url + "?" + query_string
return redirect(auth_url)
@app.route('/setup', methods=['GET'])
def setup(request):
valid = validate(request.args)
return valid
def validate(signed_params):
steam_login_url_base = "https://steamcommunity.com/openid/login"
params = {
"openid.assoc_handle": signed_params["openid.assoc_handle"],
"openid.sig": signed_params["openid.sig"],
"openid.ns": signed_params["openid.ns"],
"openid.mode": "check_authentication"
}
signed_params.update(params)
signed_params["openid.mode"] = "check_authentication"
signed_params["openid.signed"] = signed_params["openid.signed"]
r = requests.post(steam_login_url_base, data=signed_params)
if "is_valid:true" in r.text:
return True
# this fucntion should always return false if the payload is not valid
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment