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

(-)a/Koha/REST/V1/OAuth/Client.pm (-7 / +18 lines)
Lines 42-47 Controller method handling login requests Link Here
42
42
43
sub login {
43
sub login {
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
    Koha::Logger->get->debug("referer " . $c->referer . "HAHA" );
45
46
46
    my $provider  = $c->param('provider_code');
47
    my $provider  = $c->param('provider_code');
47
    my $interface = $c->param('interface');
48
    my $interface = $c->param('interface');
Lines 50-64 sub login { Link Here
50
51
51
    my $uri;
52
    my $uri;
52
    my $redirect_url;
53
    my $redirect_url;
54
    my $referrer_url;
53
55
54
    if ( $interface eq 'opac' ) {
56
    if ( $interface eq 'opac' ) {
55
        $redirect_url = C4::Context->preference('OPACBaseURL') . '/api/v1/public/oauth/login/';
57
        my $host = C4::Context->preference('OPACBaseURL');
56
        if ( C4::Context->preference('OpacPublic') ) {
58
        $redirect_url = $host . '/api/v1/public/oauth/login/';
57
            $uri = '/cgi-bin/koha/opac-user.pl';
59
        # Determine that the referring_url is on our server
58
        } else {
60
        if ( $referrer_url =~ /^$host/ ) {
59
            $uri = '/cgi-bin/koha/opac-main.pl';
61
            # Strip out the logout tag
62
		    my $regex = qr/logout\.x=1/mp;
63
		    $uri = $referrer_url =~ s/$regex//rg;
64
		} else {
65
            if ( C4::Context->preference('OpacPublic') ) {
66
                $uri = '/cgi-bin/koha/opac-user.pl';
67
            } else {
68
                $uri = '/cgi-bin/koha/opac-main.pl';
69
            }
60
        }
70
        }
61
    } else {
71
    } else { # Staff can't access anything until they login, so no need to bother with referring URL
62
        $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/';
72
        $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/';
63
        $uri = '/cgi-bin/koha/mainpage.pl';
73
        $uri = '/cgi-bin/koha/mainpage.pl';
64
    }
74
    }
Lines 97-102 sub login { Link Here
97
    else {
107
    else {
98
        # initial request, generate CSRF token
108
        # initial request, generate CSRF token
99
        $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } );
109
        $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } );
110
        my $r = $c->req->headers->referrer;
111
        $c->session({referrer => $r});
100
    }
112
    }
101
113
102
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
114
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
103
- 

Return to bug 34164