You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Token request with Bearer returns error #4080
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.
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)
Activity
joragua commentedon May 22, 2025
Things to keep in mind 🤔
Authorizationheader that is set in the client (OwncloudClient)TokenRequestRemoteOperationis the only operation in which anAuthorizationheader is added with.addRequestHeader(...)/konnect/v1/tokencontains anAuthorizationheader before executing it in the network client.The bug is located in these lines (
OwncloudClient):On the first attempt to log in with an account, a
Basictoken will be sent in theAuthorizationheader 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 aBearertoken will be sent in theAuthorizationheader of the request. That is wrong! The token should beBasiclike the first attempt. The solution is: check in the client if the network request doesn't come fromTokenRequestRemoteOperationbefore setting theAuthorizationheader.In case the method cames from
TokenRequestRemoteOperationthe header will not be replaced (Basictoken will be used). In other case, theAuthorizationheader will be set with aBearertoken (necessary to execute remote operations)