mod_http_oauth2/mod_http_oauth2.lua
changeset 5189 09d6bbd6c8a4
parent 5186 20ba6340f524
child 5190 fa3059e653fa
equal deleted inserted replaced
5188:313937349fbc 5189:09d6bbd6c8a4
    92 	return json.encode(new_access_token(granted_jid, granted_scopes, nil));
    92 	return json.encode(new_access_token(granted_jid, granted_scopes, nil));
    93 end
    93 end
    94 
    94 
    95 function response_type_handlers.code(params, granted_jid)
    95 function response_type_handlers.code(params, granted_jid)
    96 	if not params.client_id then return oauth_error("invalid_request", "missing 'client_id'"); end
    96 	if not params.client_id then return oauth_error("invalid_request", "missing 'client_id'"); end
    97 	if not params.redirect_uri then return oauth_error("invalid_request", "missing 'redirect_uri'"); end
       
    98 
    97 
    99 	local client_owner, client_host, client_id = jid.prepped_split(params.client_id);
    98 	local client_owner, client_host, client_id = jid.prepped_split(params.client_id);
   100 	if client_host ~= module.host then
    99 	if client_host ~= module.host then
   101 		return oauth_error("invalid_client", "incorrect credentials");
   100 		return oauth_error("invalid_client", "incorrect credentials");
   102 	end
   101 	end
   116 	});
   115 	});
   117 	if not ok then
   116 	if not ok then
   118 		return {status_code = 429};
   117 		return {status_code = 429};
   119 	end
   118 	end
   120 
   119 
   121 	local redirect = url.parse(params.redirect_uri);
   120 	local redirect = url.parse(params.redirect_uri or client.redirect_uri);
   122 	local query = http.formdecode(redirect.query or "");
   121 	local query = http.formdecode(redirect.query or "");
   123 	if type(query) ~= "table" then query = {}; end
   122 	if type(query) ~= "table" then query = {}; end
   124 	table.insert(query, { name = "code", value = code })
   123 	table.insert(query, { name = "code", value = code })
   125 	if params.state then
   124 	if params.state then
   126 		table.insert(query, { name = "state", value = params.state });
   125 		table.insert(query, { name = "state", value = params.state });