line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::OAuth2::Schema::Result::RefreshToken; |
2
|
8
|
|
|
8
|
|
4811
|
use warnings; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
331
|
|
3
|
8
|
|
|
8
|
|
56
|
use strict; |
|
8
|
|
|
|
|
35
|
|
|
8
|
|
|
|
|
241
|
|
4
|
8
|
|
|
8
|
|
54
|
use parent 'DBIx::Class'; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: A table for registering refresh tokens |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw(Core)); |
9
|
|
|
|
|
|
|
__PACKAGE__->table('refresh_token'); |
10
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
11
|
|
|
|
|
|
|
id => { data_type => 'int', is_auto_increment => 1 }, |
12
|
|
|
|
|
|
|
code_id => { data_type => 'int', is_nullable => 0 }, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key(qw(id)); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->add_unique_constraint( [qw(id code_id)] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
__PACKAGE__->belongs_to( code => 'CatalystX::OAuth2::Schema::Result::Code' => |
19
|
|
|
|
|
|
|
{ 'foreign.id' => 'self.code_id' } ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# this is a has many but will only ever return a single record |
22
|
|
|
|
|
|
|
# because of the constraint on the relationship table |
23
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
24
|
|
|
|
|
|
|
from_access_token_map => |
25
|
|
|
|
|
|
|
'CatalystX::OAuth2::Schema::Result::AccessTokenToRefreshToken' => { |
26
|
|
|
|
|
|
|
'foreign.refresh_token_id' => 'self.id', |
27
|
|
|
|
|
|
|
'foreign.code_id' => 'self.code_id' |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
__PACKAGE__->many_to_many( |
31
|
|
|
|
|
|
|
from_access_token_map_m2m => from_access_token_map => 'access_token' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# this is a has many but will only ever return a single record |
34
|
|
|
|
|
|
|
# because of the constraint on the relationship table |
35
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
36
|
|
|
|
|
|
|
to_access_token_map => |
37
|
|
|
|
|
|
|
'CatalystX::OAuth2::Schema::Result::RefreshTokenToAccessToken' => { |
38
|
|
|
|
|
|
|
'foreign.refresh_token_id' => 'self.id', |
39
|
|
|
|
|
|
|
'foreign.code_id' => 'self.code_id' |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
__PACKAGE__->many_to_many( |
43
|
|
|
|
|
|
|
to_access_token_map_m2m => to_access_token_map => 'access_token' ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
0
|
0
|
sub from_access_token { shift->from_access_token_map_m2m->first } |
46
|
2
|
|
|
2
|
0
|
12238
|
sub to_access_token { shift->to_access_token_map_m2m->first } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub create_access_token { |
49
|
2
|
|
|
2
|
0
|
47
|
my ($self) = @_; |
50
|
2
|
|
|
|
|
59
|
my $code = $self->code; |
51
|
2
|
|
|
|
|
11790
|
my $token; |
52
|
|
|
|
|
|
|
$self->result_source->storage->txn_do( |
53
|
|
|
|
|
|
|
sub { |
54
|
|
|
|
|
|
|
# create a new token from this refresh token |
55
|
2
|
|
|
2
|
|
1196
|
$token = $code->tokens->create( |
56
|
|
|
|
|
|
|
{ from_refresh_token_map => [ { refresh_token => $self } ] } ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# create a new refresh token and add it to the new token |
59
|
2
|
|
|
|
|
22994
|
my $refresh = $code->refresh_tokens->create( {} ); |
60
|
2
|
|
|
|
|
6891
|
$token->to_refresh_token_map->create( |
61
|
|
|
|
|
|
|
{ code => $code, refresh_token => $refresh } ); |
62
|
|
|
|
|
|
|
} |
63
|
2
|
|
|
|
|
15
|
); |
64
|
2
|
|
|
|
|
14560
|
return $token; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# if we have already created a token from this refresh, de-activate it |
68
|
1
|
|
|
1
|
0
|
12068
|
sub is_active { !shift->to_access_token_map->count } |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
2
|
0
|
18695
|
sub as_string { shift->id } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
CatalystX::OAuth2::Schema::Result::RefreshToken - A table for registering refresh tokens |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.001007 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Eden Cardim <edencardim@gmail.com> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Suretec Systems Ltd. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
95
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |