Comments (4)
You should really should study the cookbook:
https://docs.mojolicious.org/Mojolicious/Guides/Cookbook
and the browse to "[Basic authentication]" ;-)
Create e new Mojo::URL Object and provide your authentication data there:
(use the env var MOJO_CLIENT_DEBUG and set it to 1 to get additional debug output).
E.g: (Minimal Script)
use Mojo::UserAgent;
use Mojo::URL;
use Test::Most;
my $ua = Mojo::UserAgent->new;
my $url = Mojo::URL->new('https://outpost.geizhals.at/maro/testing');
my $userinfo = $url->userinfo('testing:testöööng');
my $tx = $ua->get($url);
is($tx->req->url->userinfo,$userinfo,'Userinfo parsed ok');
is($tx->res->code,200,'Code 200');
from mojo.
i extended the testcase to also include explicitely created Mojo::URLs. But it also results in a 401
use v5.38;
use Mojo::UserAgent;
use Test::Most;
use utf8;
my $ua = Mojo::UserAgent->new;
my $USERINFO = 'testing:testöööng';
my $BASEURL = 'outpost.geizhals.at/maro/testing';
my $mojo_url = Mojo::URL->new("https://$BASEURL");
$mojo_url->userinfo($USERINFO);
foreach my $url (
"https://${USERINFO}\@${BASEURL}",
"https://testing:test%C3%B6%C3%B6%C3%B6ng\@${BASEURL}",
"https://testing:test%F6%F6%F6ng\@${BASEURL}",
$mojo_url
) {
my $tx = $ua->get($url);
is($tx->req->url->userinfo,$USERINFO,'Userinfo parsed ok');
is($tx->res->code,200,'Code 200');
}
The request authorization header is the same for all four requests.
from mojo.
If any of this is a bug depends entirely on the specs. Please provide references to specific spec sections we are currently violating. A random internet service is not a valid test case.
from mojo.
According to RFC-7617 the encoding of the Authoritzation is undefined for backward-compatibility reasons and as long as it remains compatible with US-ASCII. The RFC suggests that it can be latin-1 or utf-8. Most server implementations and browsers nowadays seem to prefer the later.
It is possible to include a charset parameter in the Authorization header, which only accepts utf8 as the only valid value. In this case
The user's name is "test", and the password is the string "123"
followed by the Unicode character U+00A3 (POUND SIGN). Using the
character encoding scheme UTF-8, the user-pass becomes:
't' 'e' 's' 't' ':' '1' '2' '3' pound
74 65 73 74 3A 31 32 33 C2 A3
Encoding this octet sequence in Base64 ([RFC4648], Section 4) yields:
dGVzdDoxMjPCow==
The Authoritzation header from my tests contains 'dGVzdGluZzp0ZXN09vb2bmc=' which is latin-1 and not utf-8 encoded. The webserver i was testing against is a nginx/1.18.0 with no special configuration
server {
listen *:443 ssl;
ssl_certificate /etc/ssl/LE/outpost.geizhals.at.fullchain.pem;
ssl_certificate_key /etc/ssl/LE/outpost.geizhals.at.privkey.pem;
ssl_trusted_certificate /etc/ssl/LE/outpost.geizhals.at.fullchain.pem;
root /var/www/html;
allow all;
location /maro {
auth_basic "Maros' Reich";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
If you don't want to change Mojo useragent behaviour to use utf8 as default encoding, i suggest to honour the charset parameter in https://metacpan.org/pod/Mojo::UserAgent::Transactor#tx if it equals to utf-8
from mojo.
Related Issues (20)
- Old package separator "'" deprecated at (eval 68) line 1. HOT 2
- `requires` seemingly adds conditions to all proceeding routes. HOT 3
- v5.38 and module_true: File "/app/x.pl" did not return an application object HOT 10
- Wrong explanation in sample what escapes XML and what is not (<%= vs <%==) HOT 1
- Minimize module loading HOT 4
- One t-test fails, Perl 5.38 on Windows 10 HOT 5
- The image helper now produces absolute paths HOT 7
- Mojolicious::Lite silently ignores controller configurations due to missing default namespaces HOT 2
- Morbo issues with Mojolicious 9.34 (change in Mojo/Server.pm) HOT 1
- t/mojo/log.t fails when $ENV{PERL_UNICODE} =~ /D/
- can't run mojo file
- running mojo files HOT 2
- TLS Fingerprinting
- Use of uninitialized value $cb in method lookup at Mojo/Reactor/Poll.pm HOT 1
- Can't locate object method "" via package "Mojolicious::Validator::Validation"
- Nesting layouts fails
- URL parsed from a serialised request is never absolute
- Websocket - 101 Switching Protocols
- Feeding render with Mojo::ByteStream is broken when gzipping is triggered HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mojo.