line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenID::Lite::Extension::SREG::Request; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
521
|
use Any::Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use List::MoreUtils qw(any none); |
5
|
|
|
|
|
|
|
use Carp (); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'OpenID::Lite::Extension::Request'; |
8
|
|
|
|
|
|
|
with 'OpenID::Lite::Role::ErrorHandler'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use OpenID::Lite::Extension::SREG qw(SREG_NS_1_0 SREG_NS_1_1 SREG_NS_ALIAS); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '_required' => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef', |
15
|
|
|
|
|
|
|
default => sub { [] }, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has '_optional' => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => 'ArrayRef', |
21
|
|
|
|
|
|
|
default => sub { [] }, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'policy_url' => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
isa => 'Str', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'ns_url' => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => 'Str', |
32
|
|
|
|
|
|
|
default => sub {SREG_NS_1_1}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @SREG_FIELDS = qw( |
36
|
|
|
|
|
|
|
fullname |
37
|
|
|
|
|
|
|
nickname |
38
|
|
|
|
|
|
|
dob |
39
|
|
|
|
|
|
|
email |
40
|
|
|
|
|
|
|
gender |
41
|
|
|
|
|
|
|
postcode |
42
|
|
|
|
|
|
|
country |
43
|
|
|
|
|
|
|
language |
44
|
|
|
|
|
|
|
timezone |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
override 'append_to_params' => sub { |
48
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
49
|
|
|
|
|
|
|
$params->register_extension_namespace( SREG_NS_ALIAS, $self->ns_url ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $required = $self->_required; |
52
|
|
|
|
|
|
|
$params->set_extension( SREG_NS_ALIAS, 'required', |
53
|
|
|
|
|
|
|
join( ',', @$required ) ) |
54
|
|
|
|
|
|
|
if @$required > 0; |
55
|
|
|
|
|
|
|
my $optional = $self->_optional; |
56
|
|
|
|
|
|
|
$params->set_extension( SREG_NS_ALIAS, 'optional', |
57
|
|
|
|
|
|
|
join( ',', @$optional ) ) |
58
|
|
|
|
|
|
|
if @$optional > 0; |
59
|
|
|
|
|
|
|
$params->set_extension( SREG_NS_ALIAS, 'policy_url', $self->policy_url ) |
60
|
|
|
|
|
|
|
if $self->policy_url; |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub check_field_name { |
64
|
|
|
|
|
|
|
my ( $self, $field_name ) = @_; |
65
|
|
|
|
|
|
|
return ( $field_name && ( any { $_ eq $field_name } @SREG_FIELDS ) ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub request_field { |
69
|
|
|
|
|
|
|
my ( $self, $field_name, $required ) = @_; |
70
|
|
|
|
|
|
|
$self->check_field_name($field_name) |
71
|
|
|
|
|
|
|
or return $self->ERROR( sprintf q{Invalid field-name for SREG, "%s"}, |
72
|
|
|
|
|
|
|
$field_name ); |
73
|
|
|
|
|
|
|
my $required_fields = $self->_required; |
74
|
|
|
|
|
|
|
my $optional_fields = $self->_optional; |
75
|
|
|
|
|
|
|
return if ( any { $_ eq $field_name } @$required_fields ); |
76
|
|
|
|
|
|
|
if ( any { $_ eq $field_name } @$optional_fields ) { |
77
|
|
|
|
|
|
|
return unless $required; |
78
|
|
|
|
|
|
|
my @new_optional = grep { $_ ne $field_name } @$optional_fields; |
79
|
|
|
|
|
|
|
$optional_fields = \@new_optional; |
80
|
|
|
|
|
|
|
$self->_optional($optional_fields); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
if ($required) { |
83
|
|
|
|
|
|
|
push( @$required_fields, $field_name ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
|
|
|
|
|
|
push( @$optional_fields, $field_name ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub from_provider_response { |
91
|
|
|
|
|
|
|
my ( $class, $res ) = @_; |
92
|
|
|
|
|
|
|
my $message = $res->req_params->copy(); |
93
|
|
|
|
|
|
|
my $ns_url = SREG_NS_1_1; |
94
|
|
|
|
|
|
|
my $alias = $message->get_ns_alias($ns_url); |
95
|
|
|
|
|
|
|
unless ($alias) { |
96
|
|
|
|
|
|
|
$ns_url = SREG_NS_1_0; |
97
|
|
|
|
|
|
|
$alias = $message->get_ns_alias($ns_url); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
return unless $alias; |
100
|
|
|
|
|
|
|
my $data = $message->get_extension_args($alias) || {}; |
101
|
|
|
|
|
|
|
my $obj = $class->new( ns_url => $ns_url ); |
102
|
|
|
|
|
|
|
my $result = $obj->parse_extension_args($data); |
103
|
|
|
|
|
|
|
return $result ? $obj : undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub parse_extension_args { |
107
|
|
|
|
|
|
|
my ( $self, $args, $strict ) = @_; |
108
|
|
|
|
|
|
|
if ( $args->{required} ) { |
109
|
|
|
|
|
|
|
my @f = split( /,/, $args->{required} ); |
110
|
|
|
|
|
|
|
for my $f (@f) { |
111
|
|
|
|
|
|
|
my $result = $self->request_field( $f, 1 ); |
112
|
|
|
|
|
|
|
return if ( $strict && !$result ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
if ( $args->{optional} ) { |
116
|
|
|
|
|
|
|
my @f = split( /,/, $args->{optional} ); |
117
|
|
|
|
|
|
|
for my $f (@f) { |
118
|
|
|
|
|
|
|
my $result = $self->request_field( $f, 0 ); |
119
|
|
|
|
|
|
|
return if ( $strict && !$result ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
$self->policy_url( $args->{policy_url} ) if $args->{polici_url}; |
123
|
|
|
|
|
|
|
return 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub all_requested_fields { |
127
|
|
|
|
|
|
|
my $self = shift; |
128
|
|
|
|
|
|
|
my @fields = ( @{ $self->_required }, @{ $self->_optional } ); |
129
|
|
|
|
|
|
|
return \@fields; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
no Any::Moose; |
133
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|