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

(-)a/Koha/REST/V1/OAuth/Client.pm (-6 / +16 lines)
Lines 50-64 sub login { Link Here
50
50
51
    my $uri;
51
    my $uri;
52
    my $redirect_url;
52
    my $redirect_url;
53
    my $referrer_url;
53
54
55
    $referrer_url = $c->session('referrer');
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
        if ((defined $referrer_url) && ($referrer_url ne '') &&  ($referrer_url =~ /^$host/ )) {
60
            # Strip out the logout tag
61
            my $regex = qr/logout\.x=1/mp;
62
            $uri = $referrer_url =~ s/$regex//rg;
58
        } else {
63
        } else {
59
            $uri = '/cgi-bin/koha/opac-main.pl';
64
            if ( C4::Context->preference('OpacPublic') ) {
65
                $uri = '/cgi-bin/koha/opac-user.pl';
66
            } else {
67
                $uri = '/cgi-bin/koha/opac-main.pl';
68
            }
60
        }
69
        }
61
    } else {
70
    } 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/';
71
        $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/';
63
        $uri = '/cgi-bin/koha/mainpage.pl';
72
        $uri = '/cgi-bin/koha/mainpage.pl';
64
    }
73
    }
Lines 97-102 sub login { Link Here
97
    else {
106
    else {
98
        # initial request, generate CSRF token
107
        # initial request, generate CSRF token
99
        $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } );
108
        $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } );
109
        my $r = $c->req->headers->referrer;
110
        $c->session({referrer => $r});
100
    }
111
    }
101
112
102
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
113
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
103
- 

Return to bug 34164