view mod_auth_external_insecure/examples/python/prosody-auth-example.py @ 4270:243f7b0dbf35

mod_http_oauth2: Reduce authorization code validity time to 2 minutes RFC 6749 states > A maximum authorization code lifetime of 10 minutes is RECOMMENDED. So 15 minutes was way too long. I was thinking 5 minutes at first but since this should generally be instant, I settled on 2 minutes as a large guesstimate on how slow it might be on slow links.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Nov 2020 18:46:25 +0100
parents f84ede3e9e3b
children
line wrap: on
line source

#!/usr/bin/env python2

import sys

def auth(username, password):
	if username == "someone":
		return "1"
	return "0"

def respond(ret):
	sys.stdout.write(ret+"\n")
	sys.stdout.flush()

methods = {
	"auth": { "function": auth, "parameters": 2 }
}

while 1:
	line = sys.stdin.readline().rstrip("\n")
	method, sep, data = line.partition(":")
	if method in methods:
		method_info = methods[method]
		split_data = data.split(":", method_info["parameters"])
		if len(split_data) == method_info["parameters"]:
			respond(method_info["function"](*split_data))
		else:
			respond("error: incorrect number of parameters to method '%s'"%method)
	else:
		respond("error: method '%s' not implemented"%method)