| 1 | package Daje::Tools::JWT; | ||
| 2 | 1 | ▶ | use Mojo::Base -base, -signatures, -async_await; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | # NAME | ||
| 6 | # ==== | ||
| 7 | # | ||
| 8 | # Daje::Tools::JWT - It's module for JWT's | ||
| 9 | # | ||
| 10 | # SYNOPSIS | ||
| 11 | # ======== | ||
| 12 | # | ||
| 13 | # use Daje::Tools::JWT; | ||
| 14 | # | ||
| 15 | # DESCRIPTION | ||
| 16 | # =========== | ||
| 17 | # | ||
| 18 | # Daje::Tools::JWT is ... | ||
| 19 | # | ||
| 20 | # LICENSE | ||
| 21 | # ======= | ||
| 22 | # | ||
| 23 | # Copyright (C) janeskil1525. | ||
| 24 | # | ||
| 25 | # This library is free software; you can redistribute it and/or modify | ||
| 26 | # it under the same terms as Perl itself. | ||
| 27 | # | ||
| 28 | # AUTHOR | ||
| 29 | # ====== | ||
| 30 | # | ||
| 31 | # janeskil1525 E<lt>janeskil1525@gmail.comE<gt> | ||
| 32 | # | ||
| 33 | # | ||
| 34 | |||
| 35 | use Mojo::JWT; | ||
| 36 | |||
| 37 | our $VERSION = "0.25"; | ||
| 38 | |||
| 39 | has 'secret' => qw { lK1leAbOxGmUKdVmuMKbJtD7ru1wd2V9Y5e58zLPlL5UI4GP1AETmd7eZ3MRZEP }; | ||
| 40 | |||
| 41 | async sub encode_jwt_p($self, $claim) { | ||
| 42 | |||
| 43 | my $secret = $self->secret(); | ||
| 44 | my $jwt = Mojo::JWT->new(claims => $claim, secret => $secret)->encode; | ||
| 45 | |||
| 46 | return $jwt | ||
| 47 | } | ||
| 48 | |||
| 49 | async sub decode_jwt_p($self, $jwt) { | ||
| 50 | |||
| 51 | my $secret = $self->secret(); | ||
| 52 | my $claims = Mojo::JWT->new(secret => $secret)->decode($jwt); | ||
| 53 | |||
| 54 | return $claims; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub encode_jwt($self, $claim) { | ||
| 58 | |||
| 59 | my $secret = $self->secret(); | ||
| 60 | my $jwt = Mojo::JWT->new(claims => $claim, secret => $secret)->encode; | ||
| 61 | |||
| 62 | return $jwt | ||
| 63 | } | ||
| 64 | |||
| 65 | sub decode_jwt($self, $jwt) { | ||
| 66 | |||
| 67 | my $secret = $self->secret(); | ||
| 68 | my $claims = Mojo::JWT->new(secret => $secret)->decode($jwt); | ||
| 69 | |||
| 70 | return $claims; | ||
| 71 | } | ||
| 72 | |||
| 73 | sub companise_pkey ($self, $token) { | ||
| 74 | |||
| 75 | my $jwt_hash = $self->decode_jwt($token); | ||
| 76 | |||
| 77 | return $jwt_hash->{companies_companies_pkey}; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub companies_users_pkey ($self, $token) { | ||
| 81 | |||
| 82 | my $jwt_hash = $self->decode_jwt($token); | ||
| 83 | |||
| 84 | return ($jwt_hash->{companies_companies_pkey}, $jwt_hash->{users_users_pkey}); | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | 1; | ||
| 89 | __END__ | ||