« lib/OAuthomatic/Internal/UsageGuard.pm
↑ Summary
blib/lib/OAuthomatic/UserInteraction/ViaMicroWeb.pm »
| 1 | package OAuthomatic::Server; | ||||||||||
| 2 | # ABSTRACT: Definition of OAuth server crucial characteristics | ||||||||||
| 3 | |||||||||||
| 4 | 9 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use namespace::sweep; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | # FIXME: some formatting for _help (markdown?) | ||||||||||
| 10 | |||||||||||
| 11 | 9 | has oauth_temporary_url => ( | |||||||||
| 12 | is => 'ro', isa => 'Str', required => 1); | ||||||||||
| 13 | 9 | has oauth_authorize_page => ( | |||||||||
| 14 | is => 'ro', isa => 'Str', required => 1); | ||||||||||
| 15 | 9 | 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 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 21 | 0 | ▶ | if($self->oauth_authorize_page =~ m{^https?://(.*?)/}x) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | # print "[OAuthomatic] Calculated site_name: $1\n" if $self->debug; | ||||||||||
| 23 | 0 | return $1; | |||||||||
| 24 | } else { | ||||||||||
| 25 | 0 | 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 | 9 | }); | |||||||||
| 32 | |||||||||||
| 33 | 9 | 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 | 0 | ▶ | return $_[0]->site_name . " application access settings"; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 9 | }); | |||||||||
| 40 | |||||||||||
| 41 | 9 | 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 | 0 | ▶ | my ($self, $val, $old_val) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 51 | 0 | ▶ | OAuthomatic::Error::Generic->throw( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | ident => "Invalid parameter", | ||||||||||
| 53 | extra => "Invalid protocol_version: $val (expected 1.0 or 1.0a)") | ||||||||||
| 54 | unless $val =~ /^1\.0a?$/x; | ||||||||||
| 55 | 9 | }); | |||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | 9 | has 'signature_method' => ( | |||||||||
| 59 | is => 'ro', isa => 'Str', required => 1, default => 'HMAC-SHA1'); | ||||||||||
| 60 | |||||||||||
| 61 | # FIXME: pluggable class? | ||||||||||
| 62 | |||||||||||
| 63 | 9 | 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.0201 | ||||||||||
| 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 | ||||||||||