Mercurial > prosody-modules
comparison mod_http_oauth2/mod_http_oauth2.lua @ 5931:ca3479c67e48
mod_http_oauth2: HTTP authentication schemes are case-insensitive
According to RFC 9110 section 11
> It uses a case-insensitive token to identify the authentication scheme
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 14 Jul 2024 17:47:06 +0200 |
parents | 761142ee0ff2 |
children | 46394b327d17 |
comparison
equal
deleted
inserted
replaced
5930:acd39d33170e | 5931:ca3479c67e48 |
---|---|
696 local function get_request_credentials(request) | 696 local function get_request_credentials(request) |
697 if not request.headers.authorization then return; end | 697 if not request.headers.authorization then return; end |
698 | 698 |
699 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$"); | 699 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$"); |
700 | 700 |
701 if auth_type == "Basic" then | 701 -- As described in Section 2.3 of [RFC5234], the string Bearer is case-insensitive. |
702 -- https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-11#section-5.1.1 | |
703 auth_type = auth_type:lower(); | |
704 | |
705 if auth_type == "basic" then | |
702 local creds = base64.decode(auth_data); | 706 local creds = base64.decode(auth_data); |
703 if not creds then return; end | 707 if not creds then return; end |
704 local username, password = string.match(creds, "^([^:]+):(.*)$"); | 708 local username, password = string.match(creds, "^([^:]+):(.*)$"); |
705 if not username then return; end | 709 if not username then return; end |
706 return { | 710 return { |
707 type = "basic"; | 711 type = "basic"; |
708 username = username; | 712 username = username; |
709 password = password; | 713 password = password; |
710 }; | 714 }; |
711 elseif auth_type == "Bearer" then | 715 elseif auth_type == "bearer" then |
712 return { | 716 return { |
713 type = "bearer"; | 717 type = "bearer"; |
714 bearer_token = auth_data; | 718 bearer_token = auth_data; |
715 }; | 719 }; |
716 end | 720 end |