Skip to content

Authentication

chime-frb-api uses an ACCESS_TOKEN and an optional REFRESH_TOKEN to authorize HTTP Requests against the CHIME/FRB backends. For a deeper look at these tokens visit the developer section.

The authentication process can be reduced to the following steps:

  1. Generate tokens with proper credentials, i.e. username/password.
  2. Attach the ACCESS_TOKEN with HTTP Requests to validate them
  3. Regenerate the ACCESS_TOKEN using the REFRESH_TOKEN when it expires

How to generate tokens?

chime-frb-api manages the creation, use and refreshing of tokens automatically and always prefers to use tokens over asking for credentials. In the order of decreasing preference, chime-frb-api looks for authentication components in the following locations:

  1. Arguments passed when creating the backend object

    from chime_frb_api.backends import frb_master
    
    master = frb_master.FRBMaster(access_token=access_token, refresh_token=refresh_token)
    
  2. If no arguments are passed, chime-frb-api will then look for them in the user environment,

    FRB_MASTER_ACCESS_TOKEN=<TOKEN>
    FRB_MASTER_REFRESH_TOKEN=<TOKEN>
    FRB_MASTER_USERNAME=debug
    FRB_MASTER_PASSWORD=debug
    

    Deprecation warning

    In the future FRB_MASTER_ACCESS_TOKEN will be changing to CHIME_FRB_ACCESS_TOKEN, and FRB_MASTER_REFRESH_TOKEN will change to CHIME_FRB_REFRESH_TOKEN. For now, both can be used but former will be disabled eventually.

  3. Finally, if no arguments are passed or are available via the local environment, chime-frb-api will ask the user to generate tokens. This can be done using either of the following methods:

    • A CLI tool from the command line:
      $ frb-api generate-tokens -u tzegmott
      Enter Password: ##########
      

    or

    • From Python:
      from chime_frb_api.backends import frb_master
      
      master = frb_master.FRBMaster()
      master.API.generate_token(username=username, password=password)
      

Note

Generating a new access token using your credentials invalidates the currently issued refresh token.

User Workflow

Ideally, you should only need to generate your token once, and then save it to your environment.

$ frb-api generate-tokens -u tzegmott
Enter Password: ##########

or

from chime_frb_api.backends import frb_master

master = frb_master.FRBMaster()
master.API.generate_token(username=username, password=password)

Find your tokens

master.API.access_token "your.very.long.access.token" master.API.refresh_token "your-shorter-refresh-token"

Now you can copy the tokens into your `.bashrc` or `.bash_profile` files:

```bash
export FRB_MASTER_ACCESS_TOKEN="your.very.long.access.token"
export FRB_MASTER_REFRESH_TOKEN="your-shorter-refresh-token"