From b74fde27d3ea9b603321f5e45a143a2641f0561b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Sat, 26 Dec 2020 01:48:11 +0100
Subject: [PATCH] Pridano generovani tokenu pro jitsi

---
 cf.conf                |  9 ++++++---
 lib/CF/Helpers/Auth.pm | 25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/cf.conf b/cf.conf
index 28d0f7a..fc8e875 100644
--- a/cf.conf
+++ b/cf.conf
@@ -1,5 +1,8 @@
 {
-  secrets    => ['04283d549647774b17d10e1d75bcf16c2969673d'],
-  oauth_url  => 'https://auth.pirati.cz/auth/realms/pirati',
-  groups_url => 'https://iapi.pirati.cz/v1/groups',
+  secrets              => ['14283d549647774b17d10e1d75bcf16c2969673d'],
+  oauth_url            => 'https://auth.pirati.cz/auth/realms/pirati',
+  groups_url           => 'https://iapi.pirati.cz/v1/groups',
+  piratar_base_url     => 'https://a.pirati.cz/piratar/200/',
+  jitsi_token_secret   => 'UtfkxQEpudmCh2MKLXrRmHAXoQwg5twF',
+  jitsi_token_lifetime => 300,
 }
diff --git a/lib/CF/Helpers/Auth.pm b/lib/CF/Helpers/Auth.pm
index fe004ae..ba74f16 100644
--- a/lib/CF/Helpers/Auth.pm
+++ b/lib/CF/Helpers/Auth.pm
@@ -101,6 +101,31 @@ sub register ( $class, $self, $conf) {
         return $c->stash->{user_roles};
     });
 
+    $self->helper( jitsi_token => sub ( $c, $room='*' ) {
+        my $claims = $c->oauth_claims // return undef;
+
+        my $jwt = Mojo::JWT->new(
+            secret => $c->cfg->{jitsi_token_secret},
+            claims => {
+                aud  => 'jitsi',
+                iss  => 'cf-online',
+                sub  => 'meet.jitsi',
+                room => $room,
+                exp  => time + $c->cfg->{jitsi_token_lifetime},
+                context => {
+                    user   => {
+                        avatar => join ('',
+                            $c->cfg->{piratar_base_url},
+                            $claims->{preferred_username},
+                            '.jpg',
+                        ),
+                        name   => $claims->{name},
+                        email  => $claims->{mail},
+                    }
+                },
+            }
+        )->encode;
+    });
 }
 
 1;
-- 
GitLab