-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
303 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { KibanaRequest } from '@kbn/core/server'; | ||
|
||
// Duplicate of x-pack/plugins/security/server/authentication/http_authentication/http_authorization_header.ts | ||
// to prevent bundle being required in security_solution | ||
// FIXME: Put this in a package | ||
export class HTTPAuthorizationHeader { | ||
/** | ||
* The authentication scheme. Should be consumed in a case-insensitive manner. | ||
* https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml#authschemes | ||
*/ | ||
readonly scheme: string; | ||
|
||
/** | ||
* The authentication credentials for the scheme. | ||
*/ | ||
readonly credentials: string; | ||
|
||
constructor(scheme: string, credentials: string) { | ||
this.scheme = scheme; | ||
this.credentials = credentials; | ||
} | ||
|
||
/** | ||
* Parses request's `Authorization` HTTP header if present. | ||
* @param request Request instance to extract the authorization header from. | ||
*/ | ||
static parseFromRequest(request: KibanaRequest) { | ||
const authorizationHeaderValue = request.headers.authorization; | ||
if (!authorizationHeaderValue || typeof authorizationHeaderValue !== 'string') { | ||
return null; | ||
} | ||
|
||
const [scheme] = authorizationHeaderValue.split(/\s+/); | ||
const credentials = authorizationHeaderValue.substring(scheme.length + 1); | ||
|
||
return new HTTPAuthorizationHeader(scheme, credentials); | ||
} | ||
|
||
toString() { | ||
return `${this.scheme} ${this.credentials}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.