File Coverage

lib/OAuthomatic/Server.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package OAuthomatic::Server;
2             # ABSTRACT: Definition of OAuth server crucial characteristics
3              
4 3     3   1457 use Moose;
  0            
  0            
5             use Carp;
6             use namespace::sweep;
7              
8              
9             # FIXME: some formatting for _help (markdown?)
10              
11             has oauth_temporary_url => (
12             is => 'ro', isa => 'Str', required => 1);
13             has oauth_authorize_page => (
14             is => 'ro', isa => 'Str', required => 1);
15             has oauth_token_url => (
16             is => 'ro', isa => 'Str', required => 1);
17              
18             has site_name => (
19             is => 'ro', isa => 'Str', lazy => 1, required => 1, default => sub {
20             my $self = shift;
21             if($self->oauth_authorize_page =~ m{^https?://(.*?)/}x) {
22             # print "[OAuthomatic] Calculated site_name: $1\n" if $self->debug;
23             return $1;
24             } else {
25             OAuthomatic::Error::Generic->throw(
26             ident => "Can not detect site_name",
27             extra => "Tried guessing from "
28             . $self->oauth_authorize_page
29             . "\nPlease provide explicit site_name => ...");
30             }
31             });
32              
33             has site_client_creation_page => (
34             is => 'ro', isa => 'Str');
35              
36             has site_client_creation_desc => (
37             is => 'ro', isa => 'Str', lazy => 1, required => 1, default => sub {
38             return $_[0]->site_name . " application access settings";
39             });
40              
41             has site_client_creation_help => (
42             is => 'ro', isa => 'Str');
43              
44             # FIXME: api calls prefix (prepended whenever relative path is given anywhere)
45              
46              
47             has 'protocol_version' => (
48             is => 'ro', isa => 'Str', required => 1, default => '1.0a',
49             trigger => sub {
50             my ($self, $val, $old_val) = @_;
51             OAuthomatic::Error::Generic->throw(
52             ident => "Invalid parameter",
53             extra => "Invalid protocol_version: $val (expected 1.0 or 1.0a)")
54             unless $val =~ /^1\.0a?$/x;
55             });
56              
57              
58             has 'signature_method' => (
59             is => 'ro', isa => 'Str', required => 1, default => 'HMAC-SHA1');
60              
61             # FIXME: pluggable class?
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =head1 NAME
72              
73             OAuthomatic::Server - Definition of OAuth server crucial characteristics
74              
75             =head1 VERSION
76              
77             version 0.01
78              
79             =head1 DESCRIPTION
80              
81             Definition of specific OAuth server - all necessary URLs and some
82             additional information.
83              
84             =head1 PARAMETERS
85              
86             =head2 oauth_temporary_url
87              
88             Full address of API endpoint used to create OAuth temporary token
89             (initial step of OAuth exchange). Should be documented inside given
90             webservice API docs.
91              
92             Example: C<https://bitbucket.org/api/1.0/oauth/request_token>
93              
94             =head2 oauth_authorize_page
95              
96             Full address (without params) of web page to which user should be sent
97             to authorize application access. Should be documented inside given
98             webservice API docs.
99              
100             Example: C<https://bitbucket.org/api/1.0/oauth/authenticate>
101              
102             =head2 oauth_token_url
103              
104             Full address of API endpoint used to create OAuth token (final
105             step of OAuth exchange, executed after successful authorization).
106             Should be documented inside given webservice API docs.
107              
108             Example: C<https://bitbucket.org/api/1.0/oauth/access_token>
109              
110             =head2 site_name
111              
112             Symbolic name of the server we authorize access to. Usually domain name,
113             sometimes slightly prettified.
114              
115             Default: hostname extracted from oauth_authorize_page
116              
117             Example: C<BitBucket.com>.
118              
119             =head2 site_client_creation_page
120              
121             Address of the web page on which client key and secret can be created
122             (note, terminology varies, those may also be called I<application
123             keys> or I<consumer keys> etc). Usually this is labeled "OAuth",
124             "Developer", "Application access", "Access tokens" or similarly, and
125             can be found among security settings or developer settings.
126              
127             This parameter is optional as sometimes the page may have dynamic
128             address (for example contain user name or id in URL) or not directly
129             addressable (heavily javascripted apps).
130              
131             Example: C<https://github.com/settings/applications>
132              
133             =head2 site_client_creation_desc
134              
135             Short textual description of that page, used as link text (if
136             site_client_creation_page is known) or instead of link (if not).
137              
138             Default: C<[SiteName] application access settings>.
139              
140             =head2 site_client_creation_help
141              
142             Any extra help worth presenting to the user while he looks for app
143             keys (for example info how field names map).
144              
145             =head1 ATTRIBUTES
146              
147             =head2 protocol_version
148              
149             OAuth Protocol version supported by the site. Currently either '1.0'
150             or '1.0a' (the latter is default).
151              
152             =head2 signature_method
153              
154             OAuth signature method which shold be used. Default: HMAC-SHA1
155              
156             =head1 AUTHOR
157              
158             Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
159              
160             =head1 COPYRIGHT AND LICENSE
161              
162             This software is copyright (c) 2015 by Marcin Kasperski.
163              
164             This is free software; you can redistribute it and/or modify it under
165             the same terms as the Perl 5 programming language system itself.
166              
167             =cut