| 1 | use v5.44.0; |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use Mojolicious::Lite -signatures; |
| 6 | use Mojo::ATProto::OAuth; |
| 7 | |
| 8 | my $oauth = Mojo::ATProto::OAuth->new_localhost( |
| 9 | callback_url => "http://127.0.0.1:3000/callback", |
| 10 | scopes => ["atproto", "transition:generic"], |
| 11 | store => ["SQLite" => "file:/tmp/test.db?wal_mode=1"] |
| 12 | ); |
| 13 | |
| 14 | get "/" => sub ($c) { |
| 15 | $c->render(text => "welcome to the atwall!<br><br>log in at <a href='/login'>/login</a>"); |
| 16 | }; |
| 17 | |
| 18 | get "/login" => sub ($c) { |
| 19 | my $handle_or_did = "katproto.girlonthemoon.xyz"; |
| 20 | my $redirect_url = $oauth->start_auth_flow(identifier => $handle_or_did); |
| 21 | |
| 22 | $c->redirect_to($redirect_url); |
| 23 | }; |
| 24 | |
| 25 | get "/callback" => sub ($c) { |
| 26 | my $params = $c->req->params->to_hash; |
| 27 | my $session = $oauth->process_callback($params); |
| 28 | $c->render(text => "you are logged in as $session->{handle} ($session->{account_did})\n"); |
| 29 | }; |
| 30 | |
| 31 | app->start; |
Revision d80c44f6318446f58ccb0370285a0d98786c6166