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 (+440 lines)
Lines 128-130 Link Here
128
    x-koha-authorization:
128
    x-koha-authorization:
129
      permissions:
129
      permissions:
130
        catalogue: "1"
130
        catalogue: "1"
131
/auth/providers:
132
  get:
133
    x-mojo-to: Auth::Providers#list
134
    operationId: listAuthProviders
135
    tags:
136
      - auth_providers
137
    summary: List configured authentication providers
138
    parameters:
139
      - $ref: ../swagger.yaml#/parameters/match
140
      - $ref: ../swagger.yaml#/parameters/order_by
141
      - $ref: ../swagger.yaml#/parameters/page
142
      - $ref: ../swagger.yaml#/parameters/per_page
143
      - $ref: ../swagger.yaml#/parameters/q_param
144
      - $ref: ../swagger.yaml#/parameters/q_body
145
      - $ref: ../swagger.yaml#/parameters/q_header
146
      - $ref: ../swagger.yaml#/parameters/request_id_header
147
      - name: x-koha-embed
148
        in: header
149
        required: false
150
        description: Embed list sent as a request header
151
        type: array
152
        items:
153
          type: string
154
          enum:
155
            - domains
156
        collectionFormat: csv
157
    produces:
158
      - application/json
159
    responses:
160
      "200":
161
        description: A list of authentication providers
162
        schema:
163
          type: array
164
          items:
165
            $ref: ../swagger.yaml#/definitions/auth_provider
166
      "400":
167
        description: Bad Request
168
        schema:
169
          $ref: ../swagger.yaml#/definitions/error
170
      "403":
171
        description: Access forbidden
172
        schema:
173
          $ref: ../swagger.yaml#/definitions/error
174
      "500":
175
        description: |
176
          Internal server error. Possible `error_code` attribute values:
177
178
          * `internal_server_error`
179
        schema:
180
          $ref: ../swagger.yaml#/definitions/error
181
      "503":
182
        description: Under maintenance
183
        schema:
184
          $ref: ../swagger.yaml#/definitions/error
185
    x-koha-authorization:
186
      permissions:
187
        parameters: manage_authentication_providers
188
  post:
189
    x-mojo-to: Auth::Providers#add
190
    operationId: addAuthProvider
191
    tags:
192
      - auth_providers
193
    summary: Add a new authentication provider
194
    parameters:
195
      - name: body
196
        in: body
197
        description: |
198
          A JSON object containing OAuth provider parameters.
199
200
          The `config` object required attributes depends on the chosen `protocol`
201
202
          ## OAuth
203
204
          Requires:
205
206
          * key
207
          * secret
208
          * authorize_url
209
          * token_url
210
211
          ## OIDC
212
213
          Requires:
214
215
          * key
216
          * secret
217
          * well_known_url
218
        required: true
219
        schema:
220
          $ref: ../swagger.yaml#/definitions/auth_provider
221
    produces:
222
      - application/json
223
    responses:
224
      "201":
225
        description: The generated authentication provider
226
        schema:
227
          $ref: ../swagger.yaml#/definitions/auth_provider
228
      "400":
229
        description: Bad Request
230
        schema:
231
          $ref: ../swagger.yaml#/definitions/error
232
      "403":
233
        description: Access forbidden
234
        schema:
235
          $ref: ../swagger.yaml#/definitions/error
236
      "500":
237
        description: |
238
          Internal server error. Possible `error_code` attribute values:
239
240
          * `internal_server_error`
241
        schema:
242
          $ref: ../swagger.yaml#/definitions/error
243
      "503":
244
        description: Under maintenance
245
        schema:
246
          $ref: ../swagger.yaml#/definitions/error
247
    x-koha-authorization:
248
      permissions:
249
        parameters: manage_authentication_providers
250
"/auth/providers/{auth_provider_id}":
251
  get:
252
    x-mojo-to: Auth::Providers#get
253
    operationId: getAuthProvider
254
    tags:
255
      - auth_providers
256
    summary: Get authentication provider
257
    parameters:
258
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
259
      - name: x-koha-embed
260
        in: header
261
        required: false
262
        description: Embed list sent as a request header
263
        type: array
264
        items:
265
          type: string
266
          enum:
267
            - domains
268
        collectionFormat: csv
269
    produces:
270
      - application/json
271
    responses:
272
      "200":
273
        description: An authentication provider
274
        schema:
275
          $ref: ../swagger.yaml#/definitions/auth_provider
276
      "404":
277
        description: Object not found
278
        schema:
279
          $ref: ../swagger.yaml#/definitions/error
280
      "500":
281
        description: |
282
          Internal server error. Possible `error_code` attribute values:
283
284
          * `internal_server_error`
285
        schema:
286
          $ref: ../swagger.yaml#/definitions/error
287
      "503":
288
        description: Under maintenance
289
        schema:
290
          $ref: ../swagger.yaml#/definitions/error
291
    x-koha-authorization:
292
      permissions:
293
        parameters: manage_authentication_providers
294
  put:
295
    x-mojo-to: Auth::Providers#update
296
    operationId: updateAuthProvider
297
    tags:
298
      - auth_providers
299
    summary: Update an authentication provider
300
    parameters:
301
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
302
      - name: body
303
        in: body
304
        description: |
305
          A JSON object containing OAuth provider parameters.
306
307
          The `config` object required attributes depends on the chosen `protocol`
308
309
          ## OAuth
310
311
          Requires:
312
313
          * key
314
          * secret
315
          * authorize_url
316
          * token_url
317
318
          ## OIDC
319
320
          Requires:
321
322
          * key
323
          * secret
324
          * well_known_url
325
        required: true
326
        schema:
327
          $ref: ../swagger.yaml#/definitions/auth_provider
328
    produces:
329
      - application/json
330
    responses:
331
      "200":
332
        description: Updated authentication provider
333
        schema:
334
          $ref: ../swagger.yaml#/definitions/auth_provider
335
      "400":
336
        description: Bad Request
337
        schema:
338
          $ref: ../swagger.yaml#/definitions/error
339
      "403":
340
        description: Access forbidden
341
        schema:
342
          $ref: ../swagger.yaml#/definitions/error
343
      "404":
344
        description: Object not found
345
        schema:
346
          $ref: ../swagger.yaml#/definitions/error
347
      "500":
348
        description: |
349
          Internal server error. Possible `error_code` attribute values:
350
351
          * `internal_server_error`
352
        schema:
353
          $ref: ../swagger.yaml#/definitions/error
354
      "503":
355
        description: Under maintenance
356
        schema:
357
          $ref: ../swagger.yaml#/definitions/error
358
    x-koha-authorization:
359
      permissions:
360
        parameters: manage_authentication_providers
361
  delete:
362
    x-mojo-to: Auth::Providers#delete
363
    operationId: delAuthProvider
364
    tags:
365
      - auth_providers
366
    summary: Delete authentication provider
367
    parameters:
368
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
369
    produces:
370
      - application/json
371
    responses:
372
      "204":
373
        description: Authentication provider deleted
374
      "401":
375
        description: Authentication required
376
        schema:
377
          $ref: ../swagger.yaml#/definitions/error
378
      "403":
379
        description: Access forbidden
380
        schema:
381
          $ref: ../swagger.yaml#/definitions/error
382
      "404":
383
        description: City not found
384
        schema:
385
          $ref: ../swagger.yaml#/definitions/error
386
      "500":
387
        description: |
388
          Internal server error. Possible `error_code` attribute values:
389
390
          * `internal_server_error`
391
      "503":
392
        description: Under maintenance
393
        schema:
394
          $ref: ../swagger.yaml#/definitions/error
395
    x-koha-authorization:
396
      permissions:
397
        parameters: manage_authentication_providers
398
"/auth/providers/{auth_provider_id}/domains":
399
  get:
400
    x-mojo-to: Auth::Provider::Domains#list
401
    operationId: listAuthProviderDomains
402
    tags:
403
      - auth_providers
404
    summary: Get authentication provider configured domains
405
    parameters:
406
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
407
      - $ref: ../swagger.yaml#/parameters/match
408
      - $ref: ../swagger.yaml#/parameters/order_by
409
      - $ref: ../swagger.yaml#/parameters/page
410
      - $ref: ../swagger.yaml#/parameters/per_page
411
      - $ref: ../swagger.yaml#/parameters/q_param
412
      - $ref: ../swagger.yaml#/parameters/q_body
413
      - $ref: ../swagger.yaml#/parameters/q_header
414
      - $ref: ../swagger.yaml#/parameters/request_id_header
415
      - name: x-koha-embed
416
        in: header
417
        required: false
418
        description: Embed list sent as a request header
419
        type: array
420
        items:
421
          type: string
422
          enum:
423
            - domains
424
        collectionFormat: csv
425
    produces:
426
      - application/json
427
    responses:
428
      "200":
429
        description: An authentication provider
430
        schema:
431
          items:
432
            $ref: ../swagger.yaml#/definitions/auth_provider_domain
433
      "404":
434
        description: Object not found
435
        schema:
436
          $ref: ../swagger.yaml#/definitions/error
437
      "500":
438
        description: |
439
          Internal server error. Possible `error_code` attribute values:
440
441
          * `internal_server_error`
442
        schema:
443
          $ref: ../swagger.yaml#/definitions/error
444
      "503":
445
        description: Under maintenance
446
        schema:
447
          $ref: ../swagger.yaml#/definitions/error
448
    x-koha-authorization:
449
      permissions:
450
        parameters: manage_authentication_providers
451
  post:
452
    x-mojo-to: Auth::Provider::Domains#add
453
    operationId: addAuthProviderDomain
454
    tags:
455
      - auth_providers
456
    summary: Add an authentication provider domain
457
    parameters:
458
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
459
      - name: body
460
        in: body
461
        description: An authentication provider domain object
462
        required: true
463
        schema:
464
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
465
    produces:
466
      - application/json
467
    responses:
468
      "201":
469
        description: Updated authentication provider domain
470
        schema:
471
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
472
      "400":
473
        description: Bad Request
474
        schema:
475
          $ref: ../swagger.yaml#/definitions/error
476
      "403":
477
        description: Access forbidden
478
        schema:
479
          $ref: ../swagger.yaml#/definitions/error
480
      "404":
481
        description: Object not found
482
        schema:
483
          $ref: ../swagger.yaml#/definitions/error
484
      "500":
485
        description: |
486
          Internal server error. Possible `error_code` attribute values:
487
488
          * `internal_server_error`
489
        schema:
490
          $ref: ../swagger.yaml#/definitions/error
491
      "503":
492
        description: Under maintenance
493
        schema:
494
          $ref: ../swagger.yaml#/definitions/error
495
    x-koha-authorization:
496
      permissions:
497
        parameters: manage_authentication_providers
498
"/auth/providers/{auth_provider_id}/domains/{auth_provider_domain_id}":
499
  get:
500
    x-mojo-to: Auth::Provider::Domains#get
501
    operationId: getAuthProviderDomain
502
    tags:
503
      - auth_providers
504
    summary: Get authentication provider domain
505
    parameters:
506
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
507
      - $ref: ../swagger.yaml#/parameters/auth_provider_domain_id_pp
508
    produces:
509
      - application/json
510
    responses:
511
      "200":
512
        description: An authentication provider
513
        schema:
514
          $ref: ../swagger.yaml#/definitions/auth_provider_domain
515
      "404":
516
        description: Object not found
517
        schema:
518
          $ref: ../swagger.yaml#/definitions/error
519
      "500":
520
        description: |
521
          Internal server error. Possible `error_code` attribute values:
522
523
          * `internal_server_error`
524
        schema:
525
          $ref: ../swagger.yaml#/definitions/error
526
      "503":
527
        description: Under maintenance
528
        schema:
529
          $ref: ../swagger.yaml#/definitions/error
530
    x-koha-authorization:
531
      permissions:
532
        parameters: manage_authentication_providers
533
  delete:
534
    x-mojo-to: Auth::Provider::Domains#delete
535
    operationId: delAuthProviderDomain
536
    tags:
537
      - auth_providers
538
    summary: Delete authentication provider
539
    parameters:
540
      - $ref: ../swagger.yaml#/parameters/auth_provider_id_pp
541
      - $ref: ../swagger.yaml#/parameters/auth_provider_domain_id_pp
542
    produces:
543
      - application/json
544
    responses:
545
      "204":
546
        description: Authentication provider deleted
547
      "401":
548
        description: Authentication required
549
        schema:
550
          $ref: ../swagger.yaml#/definitions/error
551
      "403":
552
        description: Access forbidden
553
        schema:
554
          $ref: ../swagger.yaml#/definitions/error
555
      "404":
556
        description: City not found
557
        schema:
558
          $ref: ../swagger.yaml#/definitions/error
559
      "500":
560
        description: |
561
          Internal server error. Possible `error_code` attribute values:
562
563
          * `internal_server_error`
564
      "503":
565
        description: Under maintenance
566
        schema:
567
          $ref: ../swagger.yaml#/definitions/error
568
    x-koha-authorization:
569
      permissions:
570
        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 / +29 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 125-130 paths: Link Here
125
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration
129
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration
126
  /auth/two-factor/registration/verification:
130
  /auth/two-factor/registration/verification:
127
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration~1verification
131
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration~1verification
132
  /auth/providers:
133
    $ref: paths/auth.yaml#/~1auth~1providers
134
  "/auth/providers/{auth_provider_id}":
135
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}
136
  "/auth/providers/{auth_provider_id}/domains":
137
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}~1domains
138
  "/auth/providers/{auth_provider_id}/domains/{auth_provider_domain_id}":
139
    $ref: paths/auth.yaml#/~1auth~1providers~1{auth_provider_id}~1domains~1{auth_provider_domain_id}
128
  "/biblios/{biblio_id}":
140
  "/biblios/{biblio_id}":
129
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
141
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
130
  "/biblios/{biblio_id}/checkouts":
142
  "/biblios/{biblio_id}/checkouts":
Lines 269-276 paths: Link Here
269
    $ref: ./paths/libraries.yaml#/~1public~1libraries
281
    $ref: ./paths/libraries.yaml#/~1public~1libraries
270
  "/public/libraries/{library_id}":
282
  "/public/libraries/{library_id}":
271
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
283
    $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}"
272
  "/public/oauth/login/{provider}/{interface}":
284
  "/public/oauth/login/{provider_code}/{interface}":
273
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider}~1{interface}
285
    $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface}
274
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
286
  "/public/patrons/{patron_id}/article_requests/{article_request_id}":
275
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
287
    $ref: "./paths/article_requests.yaml#/~1public~1patrons~1{patron_id}~1article_requests~1{article_request_id}"
276
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
288
  "/public/patrons/{patron_id}/guarantors/can_see_charges":
Lines 324-329 parameters: Link Here
324
    name: agreement_period_id
336
    name: agreement_period_id
325
    required: true
337
    required: true
326
    type: integer
338
    type: integer
339
  auth_provider_id_pp:
340
    description: Authentication provider internal identifier
341
    in: path
342
    name: auth_provider_id
343
    required: true
344
    type: integer
345
  auth_provider_domain_id_pp:
346
    description: Authentication provider domain internal identifier
347
    in: path
348
    name: auth_provider_domain_id
349
    required: true
350
    type: integer
327
  biblio_id_pp:
351
  biblio_id_pp:
328
    description: Record internal identifier
352
    description: Record internal identifier
329
    in: path
353
    in: path
Lines 656-661 tags: Link Here
656
  - description: "Manage article requests\n"
680
  - description: "Manage article requests\n"
657
    name: article_requests
681
    name: article_requests
658
    x-displayName: Article requests
682
    x-displayName: Article requests
683
  - description: "Manage authentication providers\n"
684
    name: auth_providers
685
    x-displayName: Authentication providers
659
  - description: "Manage baskets for the acquisitions module\n"
686
  - description: "Manage baskets for the acquisitions module\n"
660
    name: baskets
687
    name: baskets
661
    x-displayName: Baskets
688
    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