BoxAuth#

class langchain_box.utilities.box.BoxAuth[source]#

Bases: BaseModel

BoxAuth.

The box-langchain package offers some flexibility to authentication. The most basic authentication method is by using a developer token. This can be found in the Box developer console on the configuration screen. This token is purposely short-lived (1 hour) and is intended for development. With this token, you can add it to your environment as BOX_DEVELOPER_TOKEN, you can pass it directly to the loader, or you can use the BoxAuth authentication helper class.

BoxAuth supports the following authentication methods:

  • Token — either a developer token or any token generated through the Box SDK

  • JWT with a service account

  • JWT with a specified user

  • CCG with a service account

  • CCG with a specified user

Note

If using JWT authentication, you will need to download the configuration from the Box developer console after generating your public/private key pair. Place this file in your application directory structure somewhere. You will use the path to this file when using the BoxAuth helper class. If you wish to use OAuth2 with the authorization_code flow, please use BoxAuthType.TOKEN with the token you have acquired.

For more information, learn about how to set up a Box application, and check out the Box authentication guide for more about our different authentication options.

Simple implementation:

To instantiate, you must provide a langchain_box.utilities.BoxAuthType.

BoxAuthType is an enum to tell BoxLoader how you wish to autheticate your Box connection.

Options are:

TOKEN - Use a developer token generated from the Box Deevloper Token.

Only recommended for development. Provide box_developer_token.

CCG - Client Credentials Grant.

provide box_client_id, box_client_secret, and box_enterprise_id or optionally box_user_id.

JWT - Use JWT for authentication. Config should be stored on the file

system accessible to your app. provide box_jwt_path. Optionally, provide box_user_id to act as a specific user

Examples:

Token

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.TOKEN,
    box_developer_token=box_developer_token
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

JWT with a service account

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.JWT,
    box_jwt_path=box_jwt_path
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

JWT with a specified user

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.JWT,
    box_jwt_path=box_jwt_path,
    box_user_id=box_user_id
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

CCG with a service account

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.CCG,
    box_client_id=box_client_id,
    box_client_secret=box_client_secret,
    box_enterprise_id=box_enterprise_id
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

CCG with a specified user

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.CCG,
    box_client_id=box_client_id,
    box_client_secret=box_client_secret,
    box_user_id=box_user_id
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param auth_type: BoxAuthType [Required]#

langchain_box.utilities.BoxAuthType. Enum describing how to authenticate against Box

param box_client_id: str | None = None#

If using BoxAuthType.CCG, provide your app’s client ID

param box_client_secret: str | None = None#

If using BoxAuthType.CCG, provide your app’s client secret

param box_developer_token: str | None = None#

If using BoxAuthType.TOKEN, provide your token here

param box_enterprise_id: str | None = None#

If using BoxAuthType.CCG, provide your enterprise ID. Only required if you are not sending box_user_id

param box_jwt_path: str | None = None#

If using BoxAuthType.JWT, provide local path to your JWT configuration file

param box_user_id: str | None = None#

If using BoxAuthType.CCG or BoxAuthType.JWT, providing box_user_id will act on behalf of a specific user

get_client() → BoxClient[source]#

Instantiate the Box SDK.

Return type:

BoxClient