mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +00:00
Allow ConfluenceLoader authorization via Personal Access Tokens (#25096)
- community: Allow authorization to Confluence with bearer token - **Description:** Allow authorization to Confluence with [Personal Access Token](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) by checking for the keys `['client_id', token: ['access_token', 'token_type']]` - **Issue:** Currently the following error occurs when using an personal access token for authorization. ```python loader = ConfluenceLoader( url=os.getenv('CONFLUENCE_URL'), oauth2={ 'token': {"access_token": os.getenv("CONFLUENCE_ACCESS_TOKEN"), "token_type": "bearer"}, 'client_id': 'client_id', }, page_ids=['12345678'], ) ``` ``` ValueError: Error(s) while validating input: ["You have either omitted require keys or added extra keys to the oauth2 dictionary. key values should be `['access_token', 'access_token_secret', 'consumer_key', 'key_cert']`"] ``` With this PR the loader runs as expected. --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
111c7df117
commit
ffa0c838d8
@ -256,22 +256,53 @@ class ConfluenceLoader(BaseLoader):
|
|||||||
x is not None for x in ((api_key or username), session, oauth2, token)
|
x is not None for x in ((api_key or username), session, oauth2, token)
|
||||||
)
|
)
|
||||||
if sum(non_null_creds) > 1:
|
if sum(non_null_creds) > 1:
|
||||||
all_names = ("(api_key, username)", "session", "oath2", "token")
|
all_names = ("(api_key, username)", "session", "oauth2", "token")
|
||||||
provided = tuple(n for x, n in zip(non_null_creds, all_names) if x)
|
provided = tuple(n for x, n in zip(non_null_creds, all_names) if x)
|
||||||
errors.append(
|
errors.append(
|
||||||
f"Cannot provide a value for more than one of: {all_names}. Received "
|
f"Cannot provide a value for more than one of: {all_names}. Received "
|
||||||
f"values for: {provided}"
|
f"values for: {provided}"
|
||||||
)
|
)
|
||||||
if oauth2 and set(oauth2.keys()) != {
|
|
||||||
"access_token",
|
if (
|
||||||
"access_token_secret",
|
oauth2
|
||||||
"consumer_key",
|
and set(oauth2.keys())
|
||||||
"key_cert",
|
== {
|
||||||
}:
|
"token",
|
||||||
|
"client_id",
|
||||||
|
}
|
||||||
|
and set(oauth2["token"].keys())
|
||||||
|
!= {
|
||||||
|
"access_token",
|
||||||
|
"token_type",
|
||||||
|
}
|
||||||
|
):
|
||||||
|
# OAuth2 token authentication
|
||||||
errors.append(
|
errors.append(
|
||||||
"You have either omitted require keys or added extra "
|
"You have either omitted require keys or added extra "
|
||||||
"keys to the oauth2 dictionary. key values should be "
|
"keys to the oauth2 dictionary. key values should be "
|
||||||
"`['access_token', 'access_token_secret', 'consumer_key', 'key_cert']`"
|
"`['client_id', 'token': ['access_token', 'token_type']]`"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
oauth2
|
||||||
|
and set(oauth2.keys())
|
||||||
|
!= {
|
||||||
|
"access_token",
|
||||||
|
"access_token_secret",
|
||||||
|
"consumer_key",
|
||||||
|
"key_cert",
|
||||||
|
}
|
||||||
|
and set(oauth2.keys())
|
||||||
|
!= {
|
||||||
|
"token",
|
||||||
|
"client_id",
|
||||||
|
}
|
||||||
|
):
|
||||||
|
errors.append(
|
||||||
|
"You have either omitted required keys or added extra "
|
||||||
|
"keys to the oauth2 dictionary. key values should be "
|
||||||
|
"`['access_token', 'access_token_secret', 'consumer_key', 'key_cert']` "
|
||||||
|
"or `['client_id', 'token': ['access_token', 'token_type']]`"
|
||||||
)
|
)
|
||||||
return errors or None
|
return errors or None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user