mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-25 18:30:00 +00:00
* Fix #2478: Update the auth header to Authorization Bearer for JWT token
This commit is contained in:
parent
2c6f6cb908
commit
52ec2e3ad1
@ -38,7 +38,8 @@ import org.openmetadata.catalog.security.auth.CatalogSecurityContext;
|
|||||||
public class JwtFilter implements ContainerRequestFilter {
|
public class JwtFilter implements ContainerRequestFilter {
|
||||||
@Context private UriInfo uriInfo;
|
@Context private UriInfo uriInfo;
|
||||||
|
|
||||||
public static final String TOKEN_HEADER = "X-Catalog-Source";
|
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
|
public static final String TOKEN_PREFIX = "Bearer";
|
||||||
private String publicKeyUri;
|
private String publicKeyUri;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -103,10 +104,14 @@ public class JwtFilter implements ContainerRequestFilter {
|
|||||||
|
|
||||||
protected static String extractToken(MultivaluedMap<String, String> headers) {
|
protected static String extractToken(MultivaluedMap<String, String> headers) {
|
||||||
LOG.debug("Request Headers:{}", headers);
|
LOG.debug("Request Headers:{}", headers);
|
||||||
String source = headers.getFirst(TOKEN_HEADER);
|
String source = headers.getFirst(AUTHORIZATION_HEADER);
|
||||||
if (Strings.isNullOrEmpty(source)) {
|
if (Strings.isNullOrEmpty(source)) {
|
||||||
throw new AuthenticationException("Not Authorized! Token not present");
|
throw new AuthenticationException("Not Authorized! Token not present");
|
||||||
}
|
}
|
||||||
return source;
|
// Extract the bearer token
|
||||||
|
if (source.startsWith(TOKEN_PREFIX)) {
|
||||||
|
return source.substring(TOKEN_PREFIX.length() + 1);
|
||||||
|
}
|
||||||
|
throw new AuthenticationException("Not Authorized! Token not present");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ class REST:
|
|||||||
url: URL = URL(base_url + "/" + version + path)
|
url: URL = URL(base_url + "/" + version + path)
|
||||||
headers = {"Content-type": "application/json"}
|
headers = {"Content-type": "application/json"}
|
||||||
if self._auth_token is not None and self._auth_token != "no_token":
|
if self._auth_token is not None and self._auth_token != "no_token":
|
||||||
headers[self.config.auth_header] = self._auth_token
|
headers[self.config.auth_header] = f"Bearer {self._auth_token}"
|
||||||
opts = {
|
opts = {
|
||||||
"headers": headers,
|
"headers": headers,
|
||||||
# Since we allow users to set endpoint URL via env var,
|
# Since we allow users to set endpoint URL via env var,
|
||||||
|
@ -138,7 +138,7 @@ class OpenMetadata(
|
|||||||
client_config: ClientConfig = ClientConfig(
|
client_config: ClientConfig = ClientConfig(
|
||||||
base_url=self.config.api_endpoint,
|
base_url=self.config.api_endpoint,
|
||||||
api_version=self.config.api_version,
|
api_version=self.config.api_version,
|
||||||
auth_header="X-Catalog-Source",
|
auth_header="Authorization",
|
||||||
auth_token=self._auth_provider.auth_token(),
|
auth_token=self._auth_provider.auth_token(),
|
||||||
)
|
)
|
||||||
self.client = REST(client_config)
|
self.client = REST(client_config)
|
||||||
|
@ -100,7 +100,7 @@ class MetadataServerConfig(ConfigModel):
|
|||||||
domain: str = None
|
domain: str = None
|
||||||
email: str = None
|
email: str = None
|
||||||
audience: str = "https://www.googleapis.com/oauth2/v4/token"
|
audience: str = "https://www.googleapis.com/oauth2/v4/token"
|
||||||
auth_header: str = "X-Catalog-Source"
|
auth_header: str = "Authorization"
|
||||||
|
|
||||||
|
|
||||||
class NoOpAuthenticationProvider(AuthenticationProvider):
|
class NoOpAuthenticationProvider(AuthenticationProvider):
|
||||||
|
@ -26,7 +26,7 @@ const axiosClient = axios.create({
|
|||||||
axiosClient.interceptors.request.use(function (config) {
|
axiosClient.interceptors.request.use(function (config) {
|
||||||
const token = cookieStorage.getItem(oidcTokenKey);
|
const token = cookieStorage.getItem(oidcTokenKey);
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers['X-Catalog-Source'] = token;
|
config.headers['Authorization'] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user