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

(-)a/Koha/REST/V1/OAuth/Client.pm (-7 / +30 lines)
Lines 42-48 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" );
46
45
47
    my $provider  = $c->param('provider_code');
46
    my $provider  = $c->param('provider_code');
48
    my $interface = $c->param('interface');
47
    my $interface = $c->param('interface');
Lines 51-67 sub login { Link Here
51
50
52
    my $uri;
51
    my $uri;
53
    my $redirect_url;
52
    my $redirect_url;
53
    my $referrer_url;
54
54
55
    $referrer_url = $c->session('auth-refer-uri');
55
    if ( $interface eq 'opac' ) {
56
    if ( $interface eq 'opac' ) {
56
        $redirect_url = C4::Context->preference('OPACBaseURL') . '/api/v1/public/oauth/login/';
57
        $redirect_url = C4::Context->preference('OPACBaseURL') . '/api/v1/public/oauth/login/';
57
        if ( C4::Context->preference('OpacPublic') ) {
58
        if ( $referrer_url ) {
58
            $uri = '/cgi-bin/koha/opac-user.pl';
59
            $uri = $referrer_url;
59
        } else {
60
        } else {
60
            $uri = '/cgi-bin/koha/opac-main.pl';
61
            if ( C4::Context->preference('OpacPublic') ) {
62
                $uri = '/cgi-bin/koha/opac-user.pl';
63
            } else {
64
                $uri = '/cgi-bin/koha/opac-main.pl';
65
            }
61
        }
66
        }
62
    } else {
67
    } else {
63
        $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/';
68
	$redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/';
64
        $uri = '/cgi-bin/koha/mainpage.pl';
69
	if ( $referrer_url ) {
70
	  $uri = $referrer_url;
71
	} else {
72
          $uri = '/cgi-bin/koha/mainpage.pl';
73
	}
65
    }
74
    }
66
75
67
    unless ( $provider_config && $provider_config->{authorize_url} ) {
76
    unless ( $provider_config && $provider_config->{authorize_url} ) {
Lines 98-103 sub login { Link Here
98
    else {
107
    else {
99
        # initial request, generate CSRF token
108
        # initial request, generate CSRF token
100
        $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
111
	# Check to see if the current referrer is part of the staff of opac interfaces, and store it if it is
112
	my $interface = $c->param('interface');
113
	my $referrer_uri = $c->req->headers->referrer;
114
	my $logoutregex = qr/logout\.x=1/mp;
115
	my $int_host;
116
	if ($interface eq 'opac') {
117
	  $int_host = C4::Context->preference('OPACBaseURL');
118
        } else {
119
	  $int_host = C4::Context->preference('staffClientBaseURL');
120
	}
121
	if ($referrer_uri && ($referrer_uri =~ /^\Q$int_host\E/ )) {
122
          $referrer_uri =~ s/$logoutregex//rg;
123
          $c->session({'auth-refer-uri' => $referrer_uri });
124
        }
101
    }
125
    }
102
126
103
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
127
    return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then(
104
- 

Return to bug 34164