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

Support multiple authorization header for REST API #1528

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions api/rest/restcore/AuthMiddleware.php
Expand Up @@ -51,14 +51,27 @@ public function __invoke( \Slim\Http\Request $request, \Slim\Http\Response $resp
}
} else {
# TODO: add an index on the token hash for the method below
$t_user_id = api_token_get_user( $t_authorization_header );

# Manage multiple authorization header (ex: Basic + token)
$authStringArray = explode(', ', $t_authorization_header);
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
$t_user_id = "";
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
$real_auth_header = "";
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
#Search for the token among the different authStrings
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
foreach ($authStringArray as $value) {
$t_user_id = api_token_get_user( $value );
if( $t_user_id !== false ) {
#Valid token found
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
$real_auth_header = $value;
break;
}
}
l2m83 marked this conversation as resolved.
Show resolved Hide resolved
if( $t_user_id === false ) {
return $response->withStatus( HTTP_STATUS_FORBIDDEN, 'API token not found' );
}

# use api token
$t_login_method = LOGIN_METHOD_API_TOKEN;
$t_password = $t_authorization_header;
$t_password = $real_auth_header;
$t_username = user_get_username( $t_user_id );
}

Expand Down