Auth0/Authentication.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 92 CC 3 SCAR 10.3
CC
3
Cov
0%
get_token
6.0
userinfo
6.0
authorize
2.0
CRAP 2.8
1 package WebService::Auth0::Authentication;
2  
3 use Moo;
4 extends 'WebService::Auth0::HTTPClient';
5  
6 has 'client_id' => (
7 is=>'ro',
8 required=>1);
9  
10 has 'client_secret' => (
11 is=>'ro',
12 predicate=>'has_client_secret',
13 required=>0);
14  
15 # I Hate to mix POD with code like this but this way I don't miss
16 # something (and it makes it easier on me to keep all these numerous
17 # methods correct
18  
19 =head1 NAME
20  
21 WebService::Auth0::Authentication::Login - Authentication API
22  
23 =head1 SYNOPSIS
24  
25 my $ua = WebService::Auth0::UA->create;
26 my $auth = WebService::Auth0::Authentication->new(
27 ua => $ua,
28 domain => $ENV{AUTH0_DOMAIN},
29 client_id => $ENV{AUTH0_CLIENT_ID} );
30  
31  
32 =head1 DESCRIPTION
33  
34 Auth0 Authentication Login Module
35  
36 =head1 METHODS
37  
38 This class defines the following methods. Unless otherwise noted
39 all methods below will add in the client_id and/or client_secret as
40 needed.
41  
42 =head2 authorize
43  
44 GET $DOMAIN/authorize
45  
46 L<https://auth0.com/docs/api/authentication#social>,
47 L<https://auth0.com/docs/api/authentication#database-ad-ldap-passive->,
48 L<https://auth0.com/docs/api/authentication#enterprise-saml-and-others->,
49 L<https://auth0.com/docs/api/authentication?http#authorization-code-grant>.
50  
51 =cut
52  
53 sub authorize {
54 my ($self, $params) = @_;
55 $params->{client_id} = $self->client_id;
56 return $self->GET($self->uri_for('authorize', $params));
57 }
58  
59 =head2 oauth_access_token
60  
61 POST $DOMAIN/oauth/access_token
62
63 L<https://auth0.com/docs/api/authentication#social-with-provider-s-access-token>
64  
65 =cut
66  
67 sub oauth_access_token {
68 my ($self, $params) = @_;
69 $params->{client_id} = $self->client_id;
70 return $self->POST_JSON($self->uri_for('oauth','access_token'), $params);
71 }
72  
73 =head2 oauth_ro
74  
75 POST $DOMAIN/oauth/ro
76  
77 L<https://auth0.com/docs/api/authentication#database-ad-ldap-active->
78 L<https://auth0.com/docs/api/authentication?http#resource-owner>
79 L<https://auth0.com/docs/api/authentication#authenticate-user>
80  
81 =cut
82  
83 sub oauth_ro {
84 my ($self, $params) = @_;
85 $params->{client_id} = $self->client_id;
86 return $self->POST_JSON($self->uri_for('oauth','ro'), $params);
87 }
88  
89 =head2 logout
90  
91 GET $DOMAIN/v2/logout
92  
93 L<https://auth0.com/docs/api/authentication#logout>
94  
95 =cut
96  
97 sub logout {
98 my ($self, $params) = @_;
99 $params->{client_id} = $self->client_id;
100 return $self->GET($self->uri_for('v2','logout', $params));
101  
102 }
103  
104 =head2 signup
105  
106 POST $DOMAIN/dbconnections/signup
107  
108 L<https://auth0.com/docs/api/authentication#signup>
109  
110 =cut
111  
112 sub signup {
113 my ($self, $params) = @_;
114 $params->{client_id} = $self->client_id;
115 return $self->POST_JSON($self->uri_for('dbconnections','signup'), $params);
116 }
117  
118 =head2 change_db_password
119  
120 POST $DOMAIN/dbconnections/change_password
121  
122 L<https://auth0.com/docs/api/authentication?http#change-password>
123  
124 =cut
125  
126 sub change_db_password {
127 my ($self, $params) = @_;
128 $params->{client_id} = $self->client_id;
129 return $self->POST_JSON($self->uri_for('dbconnections','change_password'), $params);
130 }
131  
132 =head2 impersonation
133  
134 POST $DOMAIN/users/:user_id/impersonate
135  
136 L<https://auth0.com/docs/api/authentication#impersonation>
137  
138 =cut
139  
140 sub impersonation {
141 my ($self, $user_id, $params) = @_;
142 $params->{client_id} = $self->client_id;
143 return $self->POST_JSON($self->uri_for('users', $user_id, 'impersonate'), $params);
144 }
145  
146 =head2 impersonate
147  
148 POST $DOMAIN/users/:user_id/impersonate
149  
150 L<https://auth0.com/docs/api/authentication#delegation>
151  
152 =cut
153  
154 sub impersonate {
155 my ($self, $params) = @_;
156 $params->{client_id} = $self->client_id;
157 return $self->POST_JSON($self->uri_for('delegation'), $params);
158 }
159  
160 =head2 get_token
161  
162 POST $DOMAIN/oauth/token
163  
164 L<https://auth0.com/docs/api/authentication?http#get-token>
165  
166 =cut
167  
168 sub get_token {
169 my ($self, $params) = @_;
170 die "method requires 'client_secret'" unless $self->has_client_secret;
171 $params->{client_id} = $self->client_id;
172 $params->{client_secret} = $self->client_secret;
173 return $self->POST_JSON($self->uri_for('oauth','token'), $params);
174 }
175  
176 =head2 ws_fed_accept_request
177  
178 GET $DOMAIN/wsfed/:client_id/
179  
180 L<https://auth0.com/docs/api/authentication#accept-request22>
181  
182 =cut
183  
184 sub ws_fed_accept_request {
185 my ($self, $params) = @_;
186 return $self->GET($self->uri_for('wsfed', $self->client_id), $params);
187 }
188  
189 =head2 ws_fed_metadata
190  
191 GET $DOMAIN/wsfed/:client_id/FederationMetadata/2007-06/FederationMetadata.xml
192  
193 L<https://auth0.com/docs/api/authentication#get-metadata23>
194  
195 =cut
196  
197 sub ws_fed_metadata {
198 my ($self) = @_;
199 return $self->GET(
200 $self->uri_for('wsfed', $self->client_id, 'FederationMetadata', '2007-06', 'FederationMetadata.xml'));
201 }
202  
203 =head2 saml_accept_request
204  
205 GET $DOMAIN/samlp/:client_id
206  
207 L<https://auth0.com/docs/api/authentication#accept-request>
208  
209 =cut
210  
211 sub saml_accept_request {
212 my ($self, $params) = @_;
213 return $self->GET($self->uri_for('samlp', $self->client_id), $params);
214 }
215  
216 =head2 saml_metadata
217  
218 GET $DOMAIN/samlp/metadata/:client_id
219  
220 L<https://auth0.com/docs/api/authentication#get-metadata>
221  
222 =cut
223  
224 sub saml_metadata {
225 my ($self) = @_;
226 return $self->GET($self->uri_for('samlp', 'metadata', $self->client_id));
227 }
228  
229 =head2 initiated_sso_flow
230  
231 POST $DOMAIN/login/callback
232  
233 L<https://auth0.com/docs/api/authentication#idp-initiated-sso-flow>
234  
235 =cut
236  
237 sub initiated_sso_flow {
238 my ($self, $params) = @_;
239 return $self->POST_JSON($self->uri_for('login', 'callback'), $params);
240 }
241  
242 =head2 passwordless_start
243  
244 POST $DOMAIN/passwordless/start
245  
246 L<https://auth0.com/docs/api/authentication#get-code-or-link>
247  
248 =cut
249  
250 sub passwordless_start {
251 my ($self, $params) = @_;
252 $params->{client_id} = $self->client_id;
253 return $self->POST_JSON($self->uri_for('passwordless','start'), $params);
254 }
255  
256 =head2 userinfo
257  
258 GET $DOMAIN/userinfo
259  
260 L<https://auth0.com/docs/api/authentication#get-user-info>
261  
262 =cut
263  
264 sub userinfo {
265 my ($self, $params) = @_;
266 die "'access_token' is a required parameter" unless $params->{access_token};
267 return $self->GET(
268 $self->uri_for('userinfo'),
269 Authorization => "Bearer ${\$params->{access_token}}",
270 );
271 }
272  
273 =head2 tokeninfo
274  
275 POST $DOMAIN/tokeninfo
276  
277 L<https://auth0.com/docs/api/authentication#get-token-info>
278  
279 =cut
280  
281 sub tokeninfo {
282 my ($self, $params) = @_;
283 return $self->POST_JSON($self->uri_for('tokeninfo'), $params);
284 }
285  
286 =head1 SEE ALSO
287
288 L<WebService::Auth0>, L<https://auth0.com>.
289  
290 =head1 AUTHOR
291
292 See L<WebService::Auth0>
293
294 =head1 COPYRIGHT & LICENSE
295
296 See L<WebService::Auth0>
297  
298 =cut
299  
300 1;