Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OJS 3.4] Document CGIPassAuth setting for API Authorization #9320

Open
kswro opened this issue Sep 25, 2023 · 5 comments
Open

[OJS 3.4] Document CGIPassAuth setting for API Authorization #9320

kswro opened this issue Sep 25, 2023 · 5 comments
Assignees

Comments

@kswro
Copy link

kswro commented Sep 25, 2023

Describe the bug
I am unable to authenticate to the REST API via the Authorization Header as in the page https://docs.pkp.sfu.ca/dev/api/ojs/3.4#tag/Authentication (403 Forbidden).

> GET /journal/api/v1/issues?count=4 HTTP/1.1
> Host: ojs.dvl.to
> User-Agent: insomnia/2023.2.0
> Cookie: OJSSID=1669db1b3b95485e42542709da720e2f
> Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.ImNkMGQ1M2QxMmM3ZDY1YTA0YmE4Yzk1YjdlZGM3MWNiOTcwY2MxNzUi.XzQKQmNOdUdjvtSKa30yjQaEh6Cj9AmSYIGLJwyUMYk
> Accept: */*

* Mark bundle as not supporting multiuse

< HTTP/1.1 403 Forbidden
< Date: Mon, 25 Sep 2023 06:13:43 GMT
< Server: Apache/2.4.54 (Unix) OpenSSL/3.0.7
< X-Powered-By: PHP/8.2.1
< Via: 1.1 (null) (apache/2.4.54)
< Transfer-Encoding: chunked
< Content-Type: application/json

But, if authentication uses the apiToken parameter query, the connection to the REST API can be established (200 OK).

> GET /journal/api/v1/issues?count=4&apiToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.ImNkMGQ1M2QxMmM3ZDY1YTA0YmE4Yzk1YjdlZGM3MWNiOTcwY2MxNzUi.XzQKQmNOdUdjvtSKa30yjQaEh6Cj9AmSYIGLJwyUMYk HTTP/1.1
> Host: ojs.dvl.to
> User-Agent: insomnia/2023.2.0
> Cookie: OJSSID=1669db1b3b95485e42542709da720e2f
> Accept: */*

* Mark bundle as not supporting multiuse

< HTTP/1.1 200 OK
< Date: Mon, 25 Sep 2023 06:19:03 GMT
< Server: Apache/2.4.54 (Unix) OpenSSL/3.0.7
< X-Powered-By: PHP/8.2.1
< Access-Control-Allow-Origin: *
< Via: 1.1 (null) (apache/2.4.54)
< Content-Length: 25
< Content-Type: application/json

To Reproduce
Steps to reproduce the behavior:

  1. Fresh Install
  2. Set api_secret_key (config.inc.php)
  3. Add API Token from user profile
  4. Add the API Token in an Authorization header with every request made to the API

What application are you using?
OJS 3.4.0-3

Additional information
Tested on production server and new (fresh) local installation.

@touhidurabir
Copy link
Member

Unable to produce the issue in the latest stable 3.4.0-3 for local testing . Both the Authorization header and apiToken query param works fine .

@kswro I see that you are using insomnia api client app for testing and same for me . see the screenshot below
CleanShot 2023-09-25 at 16 59 54@2x

do you see any error in the error log file ?

@kswro
Copy link
Author

kswro commented Sep 25, 2023

Hello @touhidurabir

Thank you for your reply. I didn't find any error logs on PHP and Apache.

However, I have found a solution to this problem. From this page I learned that various Apache modules will strip the Authorization header, usually for "security reasons".

So, based on the same source, I added the line below to the .htaccess file in my OJS public folder and now I can connect to the REST API via authorization header:
CGIPassAuth on

Apart from the above lines, I also tried using other alternatives as below which also solved the problem.

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Based on what I experienced (and many others), do you think the above problems and solutions can be added to the documentation?

FYI, I'm using Apache >2.4.54 and PHP 8.2 (FPM) in this test.

@touhidurabir
Copy link
Member

@kswro I will discuss with other dev team members to see if it is possible to add few details regarding this in the doc .

@orcalator
Copy link

orcalator commented Jul 31, 2024

You should really add this note because i also experienced the same problem. If i didn't find this post i'd be spending a lot of time investigating what's going on. GG @kswro.

@kaitlinnewson kaitlinnewson reopened this Aug 13, 2024
@kaitlinnewson kaitlinnewson self-assigned this Aug 13, 2024
@kaitlinnewson kaitlinnewson changed the title [OJS 3.4] Authenticate API via Authorization Header Not Work [OJS 3.4] Document CGIPassAuth setting for API Authorization Aug 14, 2024
kaitlinnewson added a commit to kaitlinnewson/ojs that referenced this issue Oct 23, 2024
kaitlinnewson added a commit to kaitlinnewson/ojs that referenced this issue Oct 23, 2024
@kaitlinnewson
Copy link
Member

kaitlinnewson commented Oct 23, 2024

PRs for review:

@ewhanson are you the best person to review/merge this change to the API docs? I can also make the PR to the docs hub once approved.

Here's a screenshot of the change in my IDE's preview tool for easier review, where I've added the "Connection Issues" section:

Screenshot 2024-10-23 at 2 22 56 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants