Skip to content

Commit

Permalink
Allow ConfluenceLoader authorization via Personal Access Tokens (lang…
Browse files Browse the repository at this point in the history
…chain-ai#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>
  • Loading branch information
2 people authored and olgamurraft committed Aug 16, 2024
1 parent a653507 commit d997893
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions libs/community/langchain_community/document_loaders/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,53 @@ def validate_init_args(
x is not None for x in ((api_key or username), session, oauth2, token)
)
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)
errors.append(
f"Cannot provide a value for more than one of: {all_names}. Received "
f"values for: {provided}"
)
if oauth2 and set(oauth2.keys()) != {
"access_token",
"access_token_secret",
"consumer_key",
"key_cert",
}:

if (
oauth2
and set(oauth2.keys())
== {
"token",
"client_id",
}
and set(oauth2["token"].keys())
!= {
"access_token",
"token_type",
}
):
# OAuth2 token authentication
errors.append(
"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']`"
"`['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

Expand Down

0 comments on commit d997893

Please sign in to comment.