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

(-)a/Koha/REST/V1/OAuth/Client.pm (-2 / +27 lines)
Lines 24-29 use Mojo::URL; Link Here
24
use Scalar::Util qw(blessed);
24
use Scalar::Util qw(blessed);
25
use Try::Tiny;
25
use Try::Tiny;
26
use Koha::Logger;
26
use Koha::Logger;
27
use Koha::Token;
27
use URI::Escape qw(uri_escape_utf8);
28
use URI::Escape qw(uri_escape_utf8);
28
29
29
=head1 NAME
30
=head1 NAME
Lines 76-82 sub login { Link Here
76
        $provider_config->{authorize_url} = $authorize_url->to_string;
77
        $provider_config->{authorize_url} = $authorize_url->to_string;
77
    }
78
    }
78
79
79
    return $c->oauth2->get_token_p( $provider, { redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
80
    # Determine if it is a callback request, or the initial
81
    my $is_callback = $c->param('error_description') || $c->param('error') || $c->param('code');
82
83
    my $state;
84
85
    if ($is_callback) {
86
        # callback, check CSRF token
87
        unless (
88
            Koha::Token->new->check_csrf(
89
                {
90
                    session_id => $c->req->cookie('CGISESSID')->value,
91
                    token      => $c->param('state'),
92
                }
93
            )
94
          )
95
        {
96
            my $error = "wrong_csrf_token";
97
            return $c->redirect_to( $uri . "?auth_error=$error" );
98
        }
99
    }
100
    else {
101
        # initial request, generate CSRF token
102
        $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } );
103
    }
104
105
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
80
        sub {
106
        sub {
81
            return unless my $response = shift;
107
            return unless my $response = shift;
82
108
83
- 

Return to bug 33675