Skip to content

[BUG] Token request with Bearer returns error #4080

Closed

Description

@jesmrec

Steps to reproduce

  1. Add an oCIS account
  2. Add another oCIS account over the same server
  3. Repeat operation 2.

Actual behaviour

After adding >1 accounts on the same oCIS server, error Unsuccessful authorization in login view. This is happening because /konnect/v1/token request sends the Authorization header with a Bearer token instead of Basic. Token sent in request header is not valid yet because a valid token will come from the subsequent response.

Expected behaviour

Users can add as many accounts as they wish over the same or different server with no errors.

owncloud.2023-06-19.log

Pixel 2
Android 11
b86a19ea9

Activity

  1. added this to the 4.2 - Future milestone on Aug 21, 2023
  2. added
    p2-high
    on Nov 23, 2023
  3. self-assigned this
    on Dec 13, 2023
  4. added
    p3-medium
    and removed
    p2-high
    on Jan 12, 2024
  5. modified the milestones: 4.4 - Current, Backlog on Oct 4, 2024
  6. modified the milestones: Backlog, 4.6 - Next on Feb 14, 2025
  7. joragua commented on May 22, 2025

    @joragua
    Member

    Things to keep in mind 🤔

    • All operations/requests have an Authorization header that is set in the client (OwncloudClient)
    • TokenRequestRemoteOperation is the only operation in which an Authorization header is added with .addRequestHeader(...)
    • When the tokes expires, the next request after /konnect/v1/token contains an Authorization header before executing it in the network client.

    The bug is located in these lines (OwncloudClient):

    if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) {
           method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
    }
    

    On the first attempt to log in with an account, a Basic token will be sent in the Authorization header of the request. This is because the credentials have not been stored yet in the client (OwncloudClient). If you try to log in with another account that belongs to the same server, the credentials will be already stored and a Bearer token will be sent in the Authorization header of the request. That is wrong! The token should be Basic like the first attempt. The solution is: check in the client if the network request doesn't come from TokenRequestRemoteOperation before setting the Authorization header.

    private static final String KONNECT_V1_TOKEN_PATH = "/konnect/v1/token";
    
    ...
    
    if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty() && !method.getHttpUrl().encodedPath().equals(KONNECT_V1_TOKEN_PATH)) {
           method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
    }
    

    In case the method cames from TokenRequestRemoteOperation the header will not be replaced (Basic token will be used). In other case, the Authorization header will be set with a Bearer token (necessary to execute remote operations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions