View | Details | Raw Unified | Return to bug 31378
Collapse All | Expand All

(-)a/Koha/Auth/Provider.pm (-13 / +72 lines)
Lines 97-118 This method stores the passed config in JSON format. Link Here
97
sub set_config {
97
sub set_config {
98
    my ($self, $config) = @_;
98
    my ($self, $config) = @_;
99
99
100
    my @mandatory;
100
    my @mandatory = $self->mandatory_config_attributes;
101
102
    if ( $self->protocol eq 'OIDC' ) {
103
        @mandatory = qw(key secret well_known_url);
104
    }
105
    elsif ( $self->protocol eq 'OAuth' ) {
106
        @mandatory = qw(key secret authorize_url token_url);
107
    }
108
    else {
109
        Koha::Exception->throw( 'Unsupported protocol ' . $self->protocol );
110
    }
111
101
112
    for my $param (@mandatory) {
102
    for my $param (@mandatory) {
113
        unless ( defined( $config->{$param} ) ) {
103
        unless ( defined( $config->{$param} ) ) {
114
            Koha::Exceptions::MissingParameter->throw(
104
            Koha::Exceptions::MissingParameter->throw( parameter => $param );
115
                error => "The $param parameter is mandatory" );
116
        }
105
        }
117
    }
106
    }
118
107
Lines 167-174 sub set_mapping { Link Here
167
    return $self;
156
    return $self;
168
}
157
}
169
158
159
=head3 upgrade_class
160
161
    my $upgraded_object = $provider->upgrade_class
162
163
Returns a new instance of the object, with the right class.
164
165
=cut
166
167
sub upgrade_class {
168
    my ( $self ) = @_;
169
    my $protocol = $self->protocol;
170
171
    my $class = $self->protocol_to_class_mapping->{$protocol};
172
173
    Koha::Exception->throw($protocol . ' is not a valid protocol')
174
        unless $class;
175
176
    eval "require $class";
177
    return $class->_new_from_dbic( $self->_result );
178
}
179
170
=head2 Internal methods
180
=head2 Internal methods
171
181
182
=head3 to_api
183
184
    my $json = $provider->to_api;
185
186
Overloaded method that returns a JSON representation of the Koha::Auth::Provider object,
187
suitable for API output.
188
189
=cut
190
191
sub to_api {
192
    my ( $self, $params ) = @_;
193
194
    my $config  = $self->get_config;
195
    my $mapping = $self->get_mapping;
196
197
    my $json = $self->SUPER::to_api($params);
198
    $json->{config}  = $config;
199
    $json->{mapping} = $mapping;
200
201
    return $json;
202
}
203
172
=head3 _type
204
=head3 _type
173
205
174
=cut
206
=cut
Lines 177-180 sub _type { Link Here
177
    return 'AuthProvider';
209
    return 'AuthProvider';
178
}
210
}
179
211
212
=head3 protocol_to_class_mapping
213
214
    my $mapping = Koha::Auth::Provider::protocol_to_class_mapping
215
216
Internal method that returns a mapping between I<protocol> codes and
217
implementing I<classes>. To be used by B<upgrade_class>.
218
219
=cut
220
221
sub protocol_to_class_mapping {
222
    return {
223
        OAuth => 'Koha::Auth::Provider::OAuth',
224
        OIDC  => 'Koha::Auth::Provider::OIDC',
225
    };
226
}
227
228
=head3 mandatory_config_attributes
229
230
Stub method for raising exceptions on invalid protocols.
231
232
=cut
233
234
sub mandatory_config_attributes {
235
    my ($self) = @_;
236
    Koha::Exception->throw("This method needs to be subclassed");
237
}
238
180
1;
239
1;
(-)a/Koha/Auth/Provider/OAuth.pm (+65 lines)
Line 0 Link Here
1
package Koha::Auth::Provider::OAuth;
2
3
# Copyright Theke Solutions 2022
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Auth::Provider);
23
24
=head1 NAME
25
26
Koha::Auth::Provider::OAuth - Koha Auth Provider Object class
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 new
33
34
    my $oauth = Koha::Auth::Provider::OAuth->new( \%{params} );
35
36
Overloaded class to create a new OAuth provider.
37
38
=cut
39
40
sub new {
41
    my ( $class, $params ) = @_;
42
43
    $params->{protocol} = 'OAuth';
44
45
    return $class->SUPER::new($params);
46
}
47
48
=head2 Internal methods
49
50
=head3 mandatory_config_attributes
51
52
Returns a list of the mandatory config entries for the protocol.
53
54
=cut
55
56
sub mandatory_config_attributes {
57
    return qw(
58
      key
59
      secret
60
      authorize_url
61
      token_url
62
    );
63
}
64
65
1;
(-)a/Koha/Auth/Provider/OIDC.pm (+64 lines)
Line 0 Link Here
1
package Koha::Auth::Provider::OIDC;
2
3
# Copyright Theke Solutions 2022
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Auth::Provider);
23
24
=head1 NAME
25
26
Koha::Auth::Provider::OIDC - Koha Auth Provider Object class
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 new
33
34
    my $oidc = Koha::Auth::Provider::OIDC->new( \%{params} );
35
36
Overloaded class to create a new OIDC provider.
37
38
=cut
39
40
sub new {
41
    my ( $class, $params ) = @_;
42
43
    $params->{protocol} = 'OIDC';
44
45
    return $class->SUPER::new($params);
46
}
47
48
=head2 Internal methods
49
50
=head3 mandatory_config_attributes
51
52
Returns a list of the mandatory config entries for the protocol.
53
54
=cut
55
56
sub mandatory_config_attributes {
57
    return qw(
58
      key
59
      secret
60
      well_known_url
61
    );
62
}
63
64
1;
(-)a/Koha/REST/V1/Auth/Provider/Domains.pm (+233 lines)
Line 0 Link Here
1
package Koha::REST::V1::Auth::Provider::Domains;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Auth::Provider::Domains;
23
use Koha::Auth::Providers;
24
25
use Koha::Database;
26
27
use Scalar::Util qw(blessed);
28
use Try::Tiny;
29
30
=head1 NAME
31
32
Koha::REST::V1::Auth::Provider::Domains - Controller library for handling
33
authentication provider domains routes.
34
35
=head2 Operations
36
37
=head3 list
38
39
Controller method for listing authentication provider domains.
40
41
=cut
42
43
sub list {
44
    my $c = shift->openapi->valid_input or return;
45
46
    return try {
47
        my $auth_provider_id = $c->validation->param('auth_provider_id');
48
        my $provider         = Koha::Auth::Providers->find($auth_provider_id);
49
50
        unless ($provider) {
51
            return $c->render(
52
                status  => 404,
53
                openapi => {
54
                    error      => 'Object not found',
55
                    error_code => 'not_found',
56
                }
57
            );
58
        }
59
60
        my $domains_rs = $provider->domains;
61
        return $c->render(
62
            status  => 200,
63
            openapi => $c->objects->search($domains_rs)
64
        );
65
    } catch {
66
        $c->unhandled_exception($_);
67
    };
68
}
69
70
=head3 get
71
72
Controller method for retrieving an authentication provider domain.
73
74
=cut
75
76
sub get {
77
    my $c = shift->openapi->valid_input or return;
78
79
    return try {
80
81
        my $auth_provider_id = $c->validation->param('auth_provider_id');
82
        my $provider         = Koha::Auth::Providers->find($auth_provider_id);
83
84
        unless ($provider) {
85
            return $c->render(
86
                status  => 404,
87
                openapi => {
88
                    error      => 'Object not found',
89
                    error_code => 'not_found',
90
                }
91
            );
92
        }
93
94
        my $domains_rs = $provider->domains;
95
96
        my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
97
        my $domain                  = $c->objects->find( $domains_rs, $auth_provider_domain_id );
98
99
        unless ($domain) {
100
            return $c->render(
101
                status  => 404,
102
                openapi => {
103
                    error      => 'Object not found',
104
                    error_code => 'not_found',
105
                }
106
            );
107
        }
108
109
        return $c->render( status => 200, openapi => $domain );
110
    } catch {
111
        $c->unhandled_exception($_);
112
    }
113
}
114
115
=head3 add
116
117
Controller method for adding an authentication provider.
118
119
=cut
120
121
sub add {
122
    my $c = shift->openapi->valid_input or return;
123
124
    return try {
125
126
        Koha::Database->new->schema->txn_do(
127
            sub {
128
                my $domain = Koha::Auth::Provider::Domain->new_from_api( $c->validation->param('body') );
129
                $domain->store;
130
131
                $c->res->headers->location( $c->req->url->to_string . '/' . $domain->id );
132
                return $c->render(
133
                    status  => 201,
134
                    openapi => $domain->to_api
135
                );
136
            }
137
        );
138
    } catch {
139
        if ( blessed($_) and $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
140
            return $c->render(
141
                status  => 404,
142
                openapi => {
143
                    error      => 'Object not found',
144
                    error_code => 'not_found',
145
                }
146
            );
147
        }
148
149
        $c->unhandled_exception($_);
150
    };
151
}
152
153
=head3 update
154
155
Controller method for updating an authentication provider domain.
156
157
=cut
158
159
sub update {
160
    my $c = shift->openapi->valid_input or return;
161
162
    my $auth_provider_id        = $c->validation->param('auth_provider_id');
163
    my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
164
165
    my $domain = Koha::Auth::Provider::Domains->find(
166
        { auth_provider_id => $auth_provider_id, auth_provider_domain_id => $auth_provider_domain_id } );
167
168
    unless ($domain) {
169
        return $c->render(
170
            status  => 404,
171
            openapi => {
172
                error      => 'Object not found',
173
                error_code => 'not_found',
174
            }
175
        );
176
    }
177
178
    return try {
179
180
        Koha::Database->new->schema->txn_do(
181
            sub {
182
183
                $domain->set_from_api( $c->validation->param('body') );
184
                $domain->store->discard_changes;
185
186
                return $c->render(
187
                    status  => 200,
188
                    openapi => $domain->to_api
189
                );
190
            }
191
        );
192
    } catch {
193
        $c->unhandled_exception($_);
194
    };
195
}
196
197
=head3 delete
198
199
Controller method for deleting an authentication provider.
200
201
=cut
202
203
sub delete {
204
    my $c = shift->openapi->valid_input or return;
205
206
    my $auth_provider_id        = $c->validation->param('auth_provider_id');
207
    my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
208
209
    my $domain = Koha::Auth::Provider::Domains->find(
210
        { auth_provider_id => $auth_provider_id, auth_provider_domain_id => $auth_provider_domain_id } );
211
212
    unless ($domain) {
213
        return $c->render(
214
            status  => 404,
215
            openapi => {
216
                error      => 'Object not found',
217
                error_code => 'not_found',
218
            }
219
        );
220
    }
221
222
    return try {
223
        $domain->delete;
224
        return $c->render(
225
            status  => 204,
226
            openapi => q{}
227
        );
228
    } catch {
229
        $c->unhandled_exception($_);
230
    };
231
}
232
233
1;
(-)a/Koha/REST/V1/Auth/Providers.pm (+237 lines)
Line 0 Link Here
1
package Koha::REST::V1::Auth::Providers;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Auth::Provider::OAuth;
23
use Koha::Auth::Provider::OIDC;
24
use Koha::Auth::Providers;
25
26
use Koha::Database;
27
28
use Scalar::Util qw(blessed);
29
use Try::Tiny;
30
31
=head1 NAME
32
33
Koha::REST::V1::Auth::Providers - Controller library for handling
34
authentication providers routes.
35
36
=head2 Operations
37
38
=head3 list
39
40
Controller method for listing authentication providers.
41
42
=cut
43
44
sub list {
45
    my $c = shift->openapi->valid_input or return;
46
47
    return try {
48
        my $providers_rs = Koha::Auth::Providers->new;
49
        return $c->render(
50
            status  => 200,
51
            openapi => $c->objects->search($providers_rs)
52
        );
53
    } catch {
54
        $c->unhandled_exception($_);
55
    };
56
}
57
58
=head3 get
59
60
Controller method for retrieving an authentication provider.
61
62
=cut
63
64
sub get {
65
    my $c = shift->openapi->valid_input or return;
66
67
    return try {
68
69
        my $auth_provider_id = $c->validation->param('auth_provider_id');
70
        my $provider = $c->objects->find( Koha::Auth::Providers->new, $auth_provider_id );
71
72
        unless ( $provider ) {
73
            return $c->render(
74
                status  => 404,
75
                openapi => {
76
                    error      => 'Object not found',
77
                    error_code => 'not_found',
78
                }
79
            );
80
        }
81
82
        return $c->render( status => 200, openapi => $provider );
83
    }
84
    catch {
85
        $c->unhandled_exception($_);
86
    }
87
}
88
89
=head3 add
90
91
Controller method for adding an authentication provider.
92
93
=cut
94
95
sub add {
96
    my $c = shift->openapi->valid_input or return;
97
98
    return try {
99
100
        Koha::Database->new->schema->txn_do(
101
            sub {
102
103
                my $body = $c->validation->param('body');
104
105
                my $config   = delete $body->{config};
106
                my $mapping  = delete $body->{mapping};
107
                my $protocol = delete $body->{protocol};
108
109
                my $class = Koha::Auth::Provider::protocol_to_class_mapping->{$protocol};
110
111
                my $provider = $class->new_from_api( $body );
112
                $provider->store;
113
114
                $provider->set_config( $config );
115
                $provider->set_mapping( $mapping );
116
117
                $c->res->headers->location( $c->req->url->to_string . '/' . $provider->auth_provider_id );
118
                return $c->render(
119
                    status  => 201,
120
                    openapi => $provider->to_api
121
                );
122
            }
123
        );
124
    }
125
    catch {
126
        if ( blessed($_) ) {
127
            if ( $_->isa('Koha::Exceptions::MissingParameter') ) {
128
                return $c->render(
129
                    status  => 400,
130
                    openapi => {
131
                        error      => "Missing parameter config." . $_->parameter,
132
                        error_code => 'missing_parameter'
133
                    }
134
                );
135
            }
136
        }
137
138
        $c->unhandled_exception($_);
139
    };
140
}
141
142
=head3 update
143
144
Controller method for updating an authentication provider.
145
146
=cut
147
148
sub update {
149
    my $c = shift->openapi->valid_input or return;
150
151
    my $auth_provider_id = $c->validation->param('auth_provider_id');
152
    my $provider = Koha::Auth::Providers->find( $auth_provider_id );
153
154
    unless ( $provider ) {
155
        return $c->render(
156
            status  => 404,
157
            openapi => {
158
                error      => 'Object not found',
159
                error_code => 'not_found',
160
            }
161
        );
162
    }
163
164
    return try {
165
166
        Koha::Database->new->schema->txn_do(
167
            sub {
168
169
                my $body = $c->validation->param('body');
170
171
                my $config   = delete $body->{config};
172
                my $mapping  = delete $body->{mapping};
173
174
                $provider = $provider->set_from_api( $body )->upgrade_class;
175
176
                $provider->set_config( $config );
177
                $provider->set_mapping( $mapping );
178
                # set_config and set_mapping already called store()
179
                $provider->discard_changes;
180
181
                return $c->render(
182
                    status  => 200,
183
                    openapi => $provider->to_api
184
                );
185
            }
186
        );
187
    }
188
    catch {
189
        if ( blessed($_) ) {
190
            if ( $_->isa('Koha::Exceptions::MissingParameter') ) {
191
                return $c->render(
192
                    status  => 400,
193
                    openapi => {
194
                        error      => "Missing parameter config." . $_->parameter,
195
                        error_code => 'missing_parameter'
196
                    }
197
                );
198
            }
199
        }
200
201
        $c->unhandled_exception($_);
202
    };
203
}
204
205
=head3 delete
206
207
Controller method for deleting an authentication provider.
208
209
=cut
210
211
sub delete {
212
    my $c = shift->openapi->valid_input or return;
213
214
    my $provider = Koha::Auth::Providers->find( $c->validation->param('auth_provider_id') );
215
    unless ( $provider ) {
216
        return $c->render(
217
            status  => 404,
218
            openapi => {
219
                error      => 'Object not found',
220
                error_code => 'not_found',
221
            }
222
        );
223
    }
224
225
    return try {
226
        $provider->delete;
227
        return $c->render(
228
            status  => 204,
229
            openapi => q{}
230
        );
231
    }
232
    catch {
233
        $c->unhandled_exception($_);
234
    };
235
}
236
237
1;
(-)a/api/v1/swagger/definitions/auth_provider.yaml (+49 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  auth_provider_id:
5
    type: integer
6
    description: Internally assigned authentication provider identifier
7
    readOnly: true
8
  code:
9
    description: Authentication provider code
10
    type: string
11
  description:
12
    description: User-oriented description for the provider
13
    type: string
14
  protocol:
15
    description: Authentication protocol
16
    type: string
17
    enum:
18
      - OAuth
19
      - OIDC
20
      - CAS (not implemented)
21
      - LDAP (not implemented)
22
  mapping:
23
    description: Attribute mapping
24
    type:
25
      - object
26
      - "null"
27
  matchpoint:
28
    description: Patron attribute that will be used to match
29
    type: string
30
    enum:
31
      - email
32
      - userid
33
      - cardnumber
34
  config:
35
    description: Configuration
36
    type: object
37
  icon_url:
38
    description: Icon url
39
    type: string
40
  domains:
41
    description: Configured domains for the authentication provider
42
    type:
43
      - array
44
      - "null"
45
additionalProperties: false
46
required:
47
  - config
48
  - code
49
  - protocol
(-)a/api/v1/swagger/definitions/auth_provider_domain.yaml (+48 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  auth_provider_domain_id:
5
    type: integer
6
    description: Internally assigned authentication provider domain identifier
7
    readOnly: true
8
  auth_provider_id:
9
    type: integer
10
    description: Internally assigned authentication provider identifier
11
  domain:
12
    description: Matching domain ('*' used as wildcard)
13
    type:
14
      - string
15
      - "null"
16
  auto_register:
17
    description: If patrons will be generated on login if required
18
    type: boolean
19
  update_on_auth:
20
    description: If patron data is updated on login
21
    type: boolean
22
  default_library_id:
23
    description: Internal identifier for the default library to be assigned to the new patrons
24
    type:
25
      - string
26
      - "null"
27
  default_category_id:
28
    description: Internal identifier for the default patron's category
29
    type:
30
      - string
31
      - "null"
32
  allow_opac:
33
    description: If this domain can be used for OPAC login
34
    type: boolean
35
  allow_staff:
36
    description: If this domain can be used for staff login
37
    type: boolean
38
additionalProperties: false
39
required:
40
  - auth_provider_domain_id
41
  - auth_provider_id
42
  - domain
43
  - auto_register
44
  - update_on_auth
45
  - default_library_id
46
  - default_category_id
47
  - allow_opac
48
  - allow_staff
(-)a/api/v1/swagger/paths/auth.yaml (-5 / +448 lines)
Lines 1-4 Link Here
1
---
2
/auth/otp/token_delivery:
1
/auth/otp/token_delivery:
3
  post:
2
  post:
4
    x-mojo-to: TwoFactorAuth#send_otp_token
3
    x-mojo-to: TwoFactorAuth#send_otp_token
Lines 24-41 Link Here
24
      "400":
23
      "400":
25
        description: Bad Request
24
        description: Bad Request
26
        schema:
25
        schema:
27
          $ref: "../swagger.yaml#/definitions/error"
26
          $ref: ../swagger.yaml#/definitions/error
28
      "403":
27
      "403":
29
        description: Access forbidden
28
        description: Access forbidden
30
        schema:
29
        schema:
31
          $ref: "../swagger.yaml#/definitions/error"
30
          $ref: ../swagger.yaml#/definitions/error
32
      "500":
31
      "500":
33
        description: |
32
        description: |
34
          Internal server error. Possible `error_code` attribute values:
33
          Internal server error. Possible `error_code` attribute values:
35
34
36
          * `internal_server_error`
35
          * `internal_server_error`
37
        schema:
36
        schema:
38
          $ref: "../swagger.yaml#/definitions/error"
37
          $ref: ../swagger.yaml#/definitions/error
38
      "503":
39
        description: Under maintenance
40
        schema:
41
          $ref: ../swagger.yaml#/definitions/error
42
    x-koha-authorization:
43
      permissions:
44
        parameters: manage_authentication_providers
45
/auth/providers:
46
  get:
47
    x-mojo-to: Auth::Providers#list
48
    operationId: listAuthProviders
49
    tags:
50
      - auth_providers
51
    summary: List configured authentication providers
52
    parameters:
53
      - $ref: ../swagger.yaml#/parameters/match
54
      - $ref: ../swagger.yaml#/parameters/order_by
55
      - $ref: ../swagger.yaml#/parameters/page
56
      - $ref: ../swagger.yaml#/parameters/per_page
57
      - $ref: ../swagger.yaml#/parameters/q_param
58
      - $ref: ../swagger.yaml#/parameters/q_body
59
      - $ref: ../swagger.yaml#/parameters/q_header
60
      - $ref: ../swagger.yaml#/parameters/request_id_header
61
      - name: x-koha-embed
62
        in: header
63
        required: false
64
        description: Embed list sent as a request header
65
        type: array
66
        items:
67
          type: string
68
          enum:
69
            - domains
70
        collectionFormat: csv
71
    produces:
72
      - application/json
73
    responses:
74
      "200":
75
        description: A list of authentication providers
76
        schema:
77
          type: array
78
          items:
79
            $ref: ../swagger.yaml#/definitions/auth_provider
80
      "400":
81
        description: Bad Request
82
        schema:
83
          $ref: ../swagger.yaml#/definitions/error
84
      "403":
85
        description: Access forbidden
86
        schema:
87
          $ref: ../swagger.yaml#/definitions/error
88
      "500":
89
        description: |
90
          Internal server error. Possible `error_code` attribute values:
91
92
          * `internal_server_error`
93
        schema:
94
          $ref: ../swagger.yaml#/definitions/error
95
      "503":
96
        description: Under maintenance
97
        schema:
98
          $ref: ../swagger.yaml#/definitions/error
99
    x-koha-authorization:
100
      permissions:
101
        parameters: manage_authentication_providers
102
  post:
103
    x-mojo-to: Auth::Providers#add
104
    operationId: addAuthProvider
105
    tags:
106
      - auth_providers
107
    summary: Add a new authentication provider
108
    parameters:
109
      - name: body
110
        in: body
111
        description: |
112
          A JSON object containing OAuth provider parameters.
113
114
          The `config` object required attributes depends on the chosen `protocol`
115
116
          ## OAuth
117
118
          Requires:
119
120
          * key
121
          * secret
122
          * authorize_url
123
          * token_url
124
125
          ## OIDC
126
127
          Requires:
128
129
          * key
130
          * secret
131
          * well_known_url
132
        required: true
133
        schema:
134
          $ref: ../swagger.yaml#/definitions/auth_provider
135
    produces:
136
      - application/json
137
    responses:
138
      "201":
139
        description: The generated authentication provider
140
        schema:
141
          $ref: ../swagger.yaml#/definitions/auth_provider
142
      "400":
143
        description: Bad Request
144
        schema:
145
          $ref: ../swagger.yaml#/definitions/error
146
      "403":
147
        description: Access forbidden
148
        schema:
149
          $ref: ../swagger.yaml#/definitions/error
150
      "500":
151
        description: |
152
          Internal server error. Possible `error_code` attribute values:
153
154
          * `internal_server_error`
155
        schema:
156
          $ref: ../swagger.yaml#/definitions/error
157
      "503":
158
        description: Under maintenance
159
        schema:
160
          $ref: ../swagger.yaml#/definitions/error
161
    x-koha-authorization:
162
      permissions:
163
        parameters: manage_authentication_providers
164
"/auth/providers/{auth_provider_id}":
165
  get:
166
    x-mojo-to: Auth::Providers#get
167
    operationId: getAuthProvider
168
    tags:
169
      - auth_providers
170
    summary: Get authentication provider
171
    parameters:
172
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
173
      - name: x-koha-embed
174
        in: header
175
        required: false
176
        description: Embed list sent as a request header
177
        type: array
178
        items:
179
          type: string
180
          enum:
181
            - domains
182
        collectionFormat: csv
183
    produces:
184
      - application/json
185
    responses:
186
      "200":
187
        description: An authentication provider
188
        schema:
189
          $ref: ../swagger.yaml#/definitions/auth_provider
190
      "404":
191
        description: Object not found
192
        schema:
193
          $ref: ../swagger.yaml#/definitions/error
194
      "500":
195
        description: |
196
          Internal server error. Possible `error_code` attribute values:
197
198
          * `internal_server_error`
199
        schema:
200
          $ref: ../swagger.yaml#/definitions/error
201
      "503":
202
        description: Under maintenance
203
        schema:
204
          $ref: ../swagger.yaml#/definitions/error
205
    x-koha-authorization:
206
      permissions:
207
        parameters: manage_authentication_providers
208
  put:
209
    x-mojo-to: Auth::Providers#update
210
    operationId: updateAuthProvider
211
    tags:
212
      - auth_providers
213
    summary: Update an authentication provider
214
    parameters:
215
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
216
      - name: body
217
        in: body
218
        description: |
219
          A JSON object containing OAuth provider parameters.
220
221
          The `config` object required attributes depends on the chosen `protocol`
222
223
          ## OAuth
224
225
          Requires:
226
227
          * key
228
          * secret
229
          * authorize_url
230
          * token_url
231
232
          ## OIDC
233
234
          Requires:
235
236
          * key
237
          * secret
238
          * well_known_url
239
        required: true
240
        schema:
241
          $ref: ../swagger.yaml#/definitions/auth_provider
242
    produces:
243
      - application/json
244
    responses:
245
      "200":
246
        description: Updated authentication provider
247
        schema:
248
          $ref: ../swagger.yaml#/definitions/auth_provider
249
      "400":
250
        description: Bad Request
251
        schema:
252
          $ref: ../swagger.yaml#/definitions/error
253
      "403":
254
        description: Access forbidden
255
        schema:
256
          $ref: ../swagger.yaml#/definitions/error
257
      "404":
258
        description: Object not found
259
        schema:
260
          $ref: ../swagger.yaml#/definitions/error
261
      "500":
262
        description: |
263
          Internal server error. Possible `error_code` attribute values:
264
265
          * `internal_server_error`
266
        schema:
267
          $ref: ../swagger.yaml#/definitions/error
268
      "503":
269
        description: Under maintenance
270
        schema:
271
          $ref: ../swagger.yaml#/definitions/error
272
    x-koha-authorization:
273
      permissions:
274
        parameters: manage_authentication_providers
275
  delete:
276
    x-mojo-to: Auth::Providers#delete
277
    operationId: delAuthProvider
278
    tags:
279
      - auth_providers
280
    summary: Delete authentication provider
281
    parameters:
282
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
283
    produces:
284
      - application/json
285
    responses:
286
      "204":
287
        description: Authentication provider deleted
288
      "401":
289
        description: Authentication required
290
        schema:
291
          $ref: ../swagger.yaml#/definitions/error
292
      "403":
293
        description: Access forbidden
294
        schema:
295
          $ref: ../swagger.yaml#/definitions/error
296
      "404":
297
        description: City not found
298
        schema:
299
          $ref: ../swagger.yaml#/definitions/error
300
      "500":
301
        description: |
302
          Internal server error. Possible `error_code` attribute values:
303
304
          * `internal_server_error`
305
      "503":
306
        description: Under maintenance
307
        schema:
308
          $ref: ../swagger.yaml#/definitions/error
309
    x-koha-authorization:
310
      permissions:
311
        parameters: manage_authentication_providers
312
"/auth/providers/{auth_provider_id}/domains":
313
  get:
314
    x-mojo-to: Auth::Provider::Domains#list
315
    operationId: listAuthProviderDomains
316
    tags:
317
      - auth_providers
318
    summary: Get authentication provider configured domains
319
    parameters:
320
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
321
      - $ref: ../swagger.yaml#/parameters/match
322
      - $ref: ../swagger.yaml#/parameters/order_by
323
      - $ref: ../swagger.yaml#/parameters/page
324
      - $ref: ../swagger.yaml#/parameters/per_page
325
      - $ref: ../swagger.yaml#/parameters/q_param
326
      - $ref: ../swagger.yaml#/parameters/q_body
327
      - $ref: ../swagger.yaml#/parameters/q_header
328
      - $ref: ../swagger.yaml#/parameters/request_id_header
329
      - name: x-koha-embed
330
        in: header
331
        required: false
332
        description: Embed list sent as a request header
333
        type: array
334
        items:
335
          type: string
336
          enum:
337
            - domains
338
        collectionFormat: csv
339
    produces:
340
      - application/json
341
    responses:
342
      "200":
343
        description: An authentication provider
344
        schema:
345
          items:
346
            $ref: ../swagger.yaml#/definitions/auth_provider_domain
347
      "404":
348
        description: Object not found
349
        schema:
350
          $ref: ../swagger.yaml#/definitions/error
351
      "500":
352
        description: |
353
          Internal server error. Possible `error_code` attribute values:
354
355
          * `internal_server_error`
356
        schema:
357
          $ref: ../swagger.yaml#/definitions/error
358
      "503":
359
        description: Under maintenance
360
        schema:
361
          $ref: ../swagger.yaml#/definitions/error
362
    x-koha-authorization:
363
      permissions:
364
        parameters: manage_authentication_providers
365
  post:
366
    x-mojo-to: Auth::Provider::Domains#add
367
    operationId: addAuthProviderDomain
368
    tags:
369
      - auth_providers
370
    summary: Add an authentication provider domain
371
    parameters:
372
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
373
      - name: body
374
        in: body
375
        description: An authentication provider domain object
376
        required: true
377
        schema:
378
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
379
    produces:
380
      - application/json
381
    responses:
382
      "201":
383
        description: Updated authentication provider domain
384
        schema:
385
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
386
      "400":
387
        description: Bad Request
388
        schema:
389
          $ref: ../swagger.yaml#/definitions/error
390
      "403":
391
        description: Access forbidden
392
        schema:
393
          $ref: ../swagger.yaml#/definitions/error
394
      "404":
395
        description: Object not found
396
        schema:
397
          $ref: ../swagger.yaml#/definitions/error
398
      "500":
399
        description: |
400
          Internal server error. Possible `error_code` attribute values:
401
402
          * `internal_server_error`
403
        schema:
404
          $ref: ../swagger.yaml#/definitions/error
405
      "503":
406
        description: Under maintenance
407
        schema:
408
          $ref: ../swagger.yaml#/definitions/error
409
    x-koha-authorization:
410
      permissions:
411
        parameters: manage_authentication_providers
412
"/auth/providers/{auth_provider_id}/domains/{auth_provider_domain_id}":
413
  get:
414
    x-mojo-to: Auth::Provider::Domains#get
415
    operationId: getAuthProviderDomain
416
    tags:
417
      - auth_providers
418
    summary: Get authentication provider domain
419
    parameters:
420
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
421
      - $ref: ../swagger.yaml#/parameters/auth_provider_domain_id_pp
422
    produces:
423
      - application/json
424
    responses:
425
      "200":
426
        description: An authentication provider
427
        schema:
428
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
429
      "404":
430
        description: Object not found
431
        schema:
432
          $ref: ../swagger.yaml#/definitions/error
433
      "500":
434
        description: |
435
          Internal server error. Possible `error_code` attribute values:
436
437
          * `internal_server_error`
438
        schema:
439
          $ref: ../swagger.yaml#/definitions/error
440
      "503":
441
        description: Under maintenance
442
        schema:
443
          $ref: ../swagger.yaml#/definitions/error
444
    x-koha-authorization:
445
      permissions:
446
        parameters: manage_authentication_providers
447
  delete:
448
    x-mojo-to: Auth::Provider::Domains#delete
449
    operationId: delAuthProviderDomain
450
    tags:
451
      - auth_providers
452
    summary: Delete authentication provider
453
    parameters:
454
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
455
      - $ref: ../swagger.yaml#/parameters/auth_provider_domain_id_pp
456
    produces:
457
      - application/json
458
    responses:
459
      "204":
460
        description: Authentication provider deleted
461
      "401":
462
        description: Authentication required
463
        schema:
464
          $ref: ../swagger.yaml#/definitions/error
465
      "403":
466
        description: Access forbidden
467
        schema:
468
          $ref: ../swagger.yaml#/definitions/error
469
      "404":
470
        description: City not found
471
        schema:
472
          $ref: ../swagger.yaml#/definitions/error
473
      "500":
474
        description: |
475
          Internal server error. Possible `error_code` attribute values:
476
477
          * `internal_server_error`
478
      "503":
479
        description: Under maintenance
480
        schema:
481
          $ref: ../swagger.yaml#/definitions/error
39
    x-koha-authorization:
482
    x-koha-authorization:
40
      permissions:
483
      permissions:
41
        catalogue: "1"
484
        parameters: manage_authentication_providers
(-)a/api/v1/swagger/paths/oauth.yaml (+79 lines)
Lines 43-45 Link Here
43
        description: Access forbidden
43
        description: Access forbidden
44
        schema:
44
        schema:
45
          $ref: "../swagger.yaml#/definitions/error"
45
          $ref: "../swagger.yaml#/definitions/error"
46
"/oauth/login/{provider_code}/{interface}":
47
  get:
48
    x-mojo-to: OAuth::Client#login
49
    operationId: loginOAuthClient
50
    tags:
51
      - oauth
52
    summary: Login to OAuth provider
53
    produces:
54
      - application/json
55
    parameters:
56
      - name: provider_code
57
        in: path
58
        description: Code for OAuth provider
59
        required: true
60
        type: string
61
      - name: interface
62
        in: path
63
        description: Name of the interface this login is for
64
        required: true
65
        type: string
66
      - name: code
67
        in: query
68
        description: Code returned from OAuth server for Authorization Code grant
69
        required: false
70
        type: string
71
      - name: state
72
        in: query
73
        description: An opaque value used by the client to maintain state between the
74
          request and callback. This is the callback part.
75
        required: false
76
        type: string
77
      - name: scope
78
        in: query
79
        description: Scope returned by OAuth server
80
        type: string
81
      - name: prompt
82
        in: query
83
        description: Prompt returned by OAuth server
84
        type: string
85
      - name: authuser
86
        in: query
87
        description: Auth user returned by OAuth server
88
        type: string
89
      - name: error
90
        in: query
91
        description: OAuth error code
92
        type: string
93
      - name: error_description
94
        in: query
95
        description: OAuth error description
96
        type: string
97
      - name: error_uri
98
        in: query
99
        description: Web page with user friendly description of the error
100
        type: string
101
    responses:
102
      "302":
103
        description: User authorized
104
        schema:
105
          type: string
106
      "400":
107
        description: Bad Request
108
        schema:
109
          $ref: ../swagger.yaml#/definitions/error
110
      "403":
111
        description: Access forbidden
112
        schema:
113
          $ref: ../swagger.yaml#/definitions/error
114
      "500":
115
        description: |
116
          Internal server error. Possible `error_code` attribute values:
117
118
          * `internal_server_error`
119
        schema:
120
          $ref: ../swagger.yaml#/definitions/error
121
      "503":
122
        description: Under maintenance
123
        schema:
124
          $ref: ../swagger.yaml#/definitions/error
(-)a/api/v1/swagger/paths/public_oauth.yaml (-7 / +19 lines)
Lines 1-16 Link Here
1
"/public/oauth/login/{provider}/{interface}":
1
"/public/oauth/login/{provider_code}/{interface}":
2
  get:
2
  get:
3
    x-mojo-to: OAuth::Client#login
3
    x-mojo-to: OAuth::Client#login
4
    operationId: loginOAuthClient
4
    operationId: loginOAuthClientPublic
5
    tags:
5
    tags:
6
      - oauth
6
      - oauth
7
    summary: Login to OAuth provider
7
    summary: Login to OAuth provider
8
    produces:
8
    produces:
9
      - application/json
9
      - application/json
10
    parameters:
10
    parameters:
11
      - name: provider
11
      - name: provider_code
12
        in: path
12
        in: path
13
        description: Name of OAuth provider
13
        description: Code for OAuth provider
14
        required: true
14
        required: true
15
        type: string
15
        type: string
16
      - name: interface
16
      - name: interface
Lines 25-31 Link Here
25
        type: string
25
        type: string
26
      - name: state
26
      - name: state
27
        in: query
27
        in: query
28
        description: An opaque value used by the client to maintain state between the request and callback. This is the callback part.
28
        description: An opaque value used by the client to maintain state between the
29
          request and callback. This is the callback part.
29
        required: false
30
        required: false
30
        type: string
31
        type: string
31
      - name: scope
32
      - name: scope
Lines 60-67 Link Here
60
      "400":
61
      "400":
61
        description: Bad Request
62
        description: Bad Request
62
        schema:
63
        schema:
63
          $ref: "../swagger.yaml#/definitions/error"
64
          $ref: ../swagger.yaml#/definitions/error
64
      "403":
65
      "403":
65
        description: Access forbidden
66
        description: Access forbidden
66
        schema:
67
        schema:
67
          $ref: "../swagger.yaml#/definitions/error"
68
          $ref: ../swagger.yaml#/definitions/error
69
      "500":
70
        description: |
71
          Internal server error. Possible `error_code` attribute values:
72
73
          * `internal_server_error`
74
        schema:
75
          $ref: ../swagger.yaml#/definitions/error
76
      "503":
77
        description: Under maintenance
78
        schema:
79
          $ref: ../swagger.yaml#/definitions/error
(-)a/api/v1/swagger/swagger.yaml (-2 / +31 lines)
Lines 8-13 definitions: Link Here
8
    $ref: ./definitions/advancededitormacro.yaml
8
    $ref: ./definitions/advancededitormacro.yaml
9
  allows_renewal:
9
  allows_renewal:
10
    $ref: ./definitions/allows_renewal.yaml
10
    $ref: ./definitions/allows_renewal.yaml
11
  auth_provider:
12
    "$ref": ./definitions/auth_provider.yaml
13
  auth_provider_domain:
14
    "$ref": ./definitions/auth_provider_domain.yaml
11
  basket:
15
  basket:
12
    $ref: ./definitions/basket.yaml
16
    $ref: ./definitions/basket.yaml
13
  bundle_link:
17
  bundle_link:
Lines 105-110 paths: Link Here
105
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
109
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
106
  /auth/otp/token_delivery:
110
  /auth/otp/token_delivery:
107
    $ref: paths/auth.yaml#/~1auth~1otp~1token_delivery
111
    $ref: paths/auth.yaml#/~1auth~1otp~1token_delivery
112
  /auth/providers:
113
    $ref: paths/auth.yaml#/~1auth~1providers
114
  "/auth/providers/{auth_provider_id}":
115
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}
116
  "/auth/providers/{auth_provider_id}/domains":
117
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}~1domains
118
  "/auth/providers/{auth_provider_id}/domains/{auth_provider_domain_id}":
119
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}~1domains~1{auth_provider_domain_id}
108
  "/biblios/{biblio_id}":
120
  "/biblios/{biblio_id}":
109
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
121
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
110
  "/biblios/{biblio_id}/checkouts":
122
  "/biblios/{biblio_id}/checkouts":
Lines 189-194 paths: Link Here
189
    $ref: ./paths/libraries.yaml#/~1libraries
201
    $ref: ./paths/libraries.yaml#/~1libraries
190
  "/libraries/{library_id}":
202
  "/libraries/{library_id}":
191
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
203
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}"
204
  "/oauth/login/{provider}/{interface}":
205
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
192
  /oauth/token:
206
  /oauth/token:
193
    $ref: ./paths/oauth.yaml#/~1oauth~1token
207
    $ref: ./paths/oauth.yaml#/~1oauth~1token
194
  /patrons:
208
  /patrons:
Lines 219-226 paths: Link Here
219
    $ref: ./paths/libraries.yaml#/~1public~1libraries
233
    $ref: ./paths/libraries.yaml#/~1public~1libraries
220
  "/public/libraries/{library_id}":
234
  "/public/libraries/{library_id}":
221
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
235
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
222
  "/public/oauth/login/{provider}/{interface}":
236
  "/public/oauth/login/{provider_code}/{interface}":
223
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider}~1{interface}
237
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
224
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
238
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
225
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
239
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
226
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
240
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
Lines 262-267 parameters: Link Here
262
    name: advancededitormacro_id
276
    name: advancededitormacro_id
263
    required: true
277
    required: true
264
    type: integer
278
    type: integer
279
  auth_provider_id_pp:
280
    description: Authentication provider internal identifier
281
    in: path
282
    name: auth_provider_id
283
    required: true
284
    type: integer
285
  auth_provider_domain_id_pp:
286
    description: Authentication provider domain internal identifier
287
    in: path
288
    name: auth_provider_domain_id
289
    required: true
290
    type: integer
265
  biblio_id_pp:
291
  biblio_id_pp:
266
    description: Record internal identifier
292
    description: Record internal identifier
267
    in: path
293
    in: path
Lines 564-569 tags: Link Here
564
  - description: "Manage article requests\n"
590
  - description: "Manage article requests\n"
565
    name: article_requests
591
    name: article_requests
566
    x-displayName: Article requests
592
    x-displayName: Article requests
593
  - description: "Manage authentication providers\n"
594
    name: auth_providers
595
    x-displayName: Authentication providers
567
  - description: "Manage baskets for the acquisitions module\n"
596
  - description: "Manage baskets for the acquisitions module\n"
568
    name: baskets
597
    name: baskets
569
    x-displayName: Baskets
598
    x-displayName: Baskets
(-)a/t/db_dependent/Koha/Auth/Provider.t (-7 / +41 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Exception;
25
use Test::Exception;
Lines 84-89 subtest 'set_config() tests' => sub { Link Here
84
        plan tests => 4;
84
        plan tests => 4;
85
85
86
        my $provider = $builder->build_object( { class => 'Koha::Auth::Providers', value => { protocol => 'OIDC' } } );
86
        my $provider = $builder->build_object( { class => 'Koha::Auth::Providers', value => { protocol => 'OIDC' } } );
87
        $provider = $provider->upgrade_class;
87
88
88
        my $config = {
89
        my $config = {
89
            key    => 'key',
90
            key    => 'key',
Lines 93-104 subtest 'set_config() tests' => sub { Link Here
93
        throws_ok { $provider->set_config($config) }
94
        throws_ok { $provider->set_config($config) }
94
        'Koha::Exceptions::MissingParameter', 'Exception thrown on missing parameter';
95
        'Koha::Exceptions::MissingParameter', 'Exception thrown on missing parameter';
95
96
96
        is( $@->error, 'The well_known_url parameter is mandatory', 'Message is correct' );
97
        is( $@->parameter, 'well_known_url', 'Message is correct' );
97
98
98
        $config->{well_known_url} = 'https://koha-community.org/auth';
99
        $config->{well_known_url} = 'https://koha-community.org/auth';
99
100
100
        my $return = $provider->set_config($config);
101
        my $return = $provider->set_config($config);
101
        is( ref($return), 'Koha::Auth::Provider', 'Return type is correct' );
102
        is( ref($return), 'Koha::Auth::Provider::OIDC', 'Return type is correct' );
102
103
103
        is_deeply( $provider->get_config, $config, 'Configuration stored correctly' );
104
        is_deeply( $provider->get_config, $config, 'Configuration stored correctly' );
104
    };
105
    };
Lines 108-113 subtest 'set_config() tests' => sub { Link Here
108
        plan tests => 4;
109
        plan tests => 4;
109
110
110
        my $provider = $builder->build_object( { class => 'Koha::Auth::Providers', value => { protocol => 'OAuth' } } );
111
        my $provider = $builder->build_object( { class => 'Koha::Auth::Providers', value => { protocol => 'OAuth' } } );
112
        $provider = $provider->upgrade_class;
111
113
112
        my $config = {
114
        my $config = {
113
            key       => 'key',
115
            key       => 'key',
Lines 118-129 subtest 'set_config() tests' => sub { Link Here
118
        throws_ok { $provider->set_config($config) }
120
        throws_ok { $provider->set_config($config) }
119
        'Koha::Exceptions::MissingParameter', 'Exception thrown on missing parameter';
121
        'Koha::Exceptions::MissingParameter', 'Exception thrown on missing parameter';
120
122
121
        is( $@->error, 'The authorize_url parameter is mandatory', 'Message is correct' );
123
        is( $@->parameter, 'authorize_url', 'Message is correct' );
122
124
123
        $config->{authorize_url} = 'https://koha-community.org/auth/authorize';
125
        $config->{authorize_url} = 'https://koha-community.org/auth/authorize';
124
126
125
        my $return = $provider->set_config($config);
127
        my $return = $provider->set_config($config);
126
        is( ref($return), 'Koha::Auth::Provider', 'Return type is correct' );
128
        is( ref($return), 'Koha::Auth::Provider::OAuth', 'Return type is correct' );
127
129
128
        is_deeply( $provider->get_config, $config, 'Configuration stored correctly' );
130
        is_deeply( $provider->get_config, $config, 'Configuration stored correctly' );
129
    };
131
    };
Lines 137-143 subtest 'set_config() tests' => sub { Link Here
137
        throws_ok { $provider->set_config() }
139
        throws_ok { $provider->set_config() }
138
        'Koha::Exception', 'Exception thrown on unsupported protocol';
140
        'Koha::Exception', 'Exception thrown on unsupported protocol';
139
141
140
        like( "$@", qr/Unsupported protocol CAS/, 'Message is correct' );
142
        like( "$@", qr/This method needs to be subclassed/, 'Message is correct' );
141
    };
143
    };
142
144
143
    $schema->storage->txn_rollback;
145
    $schema->storage->txn_rollback;
Lines 177-179 subtest 'set_mapping() tests' => sub { Link Here
177
179
178
    $schema->storage->txn_rollback;
180
    $schema->storage->txn_rollback;
179
};
181
};
180
- 
182
183
subtest 'upgrade_class() tests' => sub {
184
185
    plan tests => 5;
186
187
    $schema->storage->txn_begin;
188
189
    my $mapping   = Koha::Auth::Provider::protocol_to_class_mapping;
190
    my @protocols = keys %{ $mapping };
191
192
    foreach my $protocol (@protocols) {
193
194
        my $provider = $builder->build_object(
195
            {
196
                class => 'Koha::Auth::Providers',
197
                value => { protocol => $protocol },
198
            }
199
        );
200
201
        is( ref($provider), 'Koha::Auth::Provider', "Base class used for $protocol" );
202
        # upgrade
203
        $provider = $provider->upgrade_class;
204
        is( ref($provider), $mapping->{$protocol}, "Class upgraded to " . $mapping->{$protocol} . "for protocol $protocol" );
205
    }
206
207
    my $provider = Koha::Auth::Provider->new({ protocol => 'Invalid' });
208
    throws_ok
209
      { $provider->upgrade }
210
      'Koha::Exception',
211
      'Exception throw on invalid protocol';
212
213
    $schema->storage->txn_rollback;
214
};

Return to bug 31378