kat

kat / atwall.pl

Last active 3 days ago

Like 0

kat revised this gist 3 days ago · d80c44f

1 file changed, 31 insertions

atwall.pl (file created)
@@ -0,0 +1,31 @@
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;