Property definitions

popcorn $ GithubLogin :: defaultinit
# Github OAuth login handler.
#
# See https://developer.github.com/v3/oauth/.
class GithubLogin
	super Handler

	# Client ID delivered by GitHub for your application.
	#
	# See https://github.com/settings/applications/new.
	var client_id: String is writable

	# The URL in your application where users will be sent after authorization.
	#
	# If `null`, the URL used in application registration will be used.
	#
	# See https://developer.github.com/v3/oauth/#redirect-urls.
	var redirect_uri: nullable String = null is writable

	# A space delimited list of scopes.
	#
	# See https://developer.github.com/v3/oauth/#scopes.
	var scope: nullable String = null is writable

	# An optional and unguessable random string.
	#
	# It is used to protect against cross-site request forgery attacks.
	var state: nullable String = null is writable

	# Allow signup at login.
	#
	# Whether or not unauthenticated users will be offered an option to sign up
	# for GitHub during the OAuth flow. The default is true.
	#
	# Use false in the case that a policy prohibits signups.
	var allow_signup = true is writable

	# Github OAuth login URL.
	var auth_url = "https://github.com/login/oauth/authorize" is writable

	# Build Github URL to OAuth service.
	fun build_auth_redirect: String do
		var url = "{auth_url}?client_id={client_id}&allow_signup={allow_signup}"
		var redirect_uri = self.redirect_uri
		if redirect_uri != null then url = "{url}&redirect_uri={redirect_uri}"
		var scope = self.scope
		if scope != null then url = "{url}&scope={scope}"
		var state = self.state
		if state != null then url = "{url}&state={state}"
		return url
	end

	redef fun get(req, res) do res.redirect build_auth_redirect
end
lib/popcorn/pop_auth.nit:84,1--136,3