Skip to main content

Used to fetch OKTA tokens for an application using web a browser that redirects to a commandline server

Project description

okta-token-fetcher

Provides a commandline script and package for getting an OKTA id_token by interacting with your browser via the commandline.

This script builds off of the dirty quick way to get a token from your browser stated here: https://developer.okta.com/docs/guides/implement-oauth-for-okta/main/#get-an-access-token-and-make-a-request .

This is done by opening a browser window that navigates to the auth server with localhost as the redirect_uri. There is an http server that is spun up for just long enough to handle the redirect request and get the id_token from the query parameters that are sent via window.hash (I suppose OKTA does this so that it can't be sent to the server itself).

Note that when using this tool your OKTA JWT will:

  • Be stored in the OS keychain if not setting --no-cache
  • Be visible in the url bar of your browser for a brief moment

Your OKTA application MUST have "http://localhost:8888" configured as one of the allowed redirect uri's for this tool to work.

As a terminal script:

usage: okta-fetch [-h] -i ISSUER -c CLIENT_ID [-s SCOPES] [-t TOKEN_TYPE] [--no-cache] [-S KEYCHAIN_SERVICE] [-u KEYCHAIN_USERNAME] [-r FINAL_REDIRECT] [-I]

options:
  -h, --help            show this help message and exit
  -i ISSUER, --issuer ISSUER
                        The auth server url. This should be only the domain and protocol. eg: https://mydomain.okta.com
  -c CLIENT_ID, --client-id CLIENT_ID
                        The client id to get a token for
  -s SCOPES, --scopes SCOPES
                        Comma delimited list of scopes to request
  -t TOKEN_TYPE, --token-type TOKEN_TYPE
                        The type of token to request
  --no-cache            Don't cache the token
  -S KEYCHAIN_SERVICE, --keychain-service KEYCHAIN_SERVICE
                        Service name to use when caching tokens to the OS keychain. Defaults to the issuer
  -u KEYCHAIN_USERNAME, --keychain-username KEYCHAIN_USERNAME
                        Username to use when caching tokens to the OS keychain. Defaults to the client ID
  -r FINAL_REDIRECT, --final-redirect FINAL_REDIRECT
                        This is where the browser will be redirected to at the end of the auth flow
  -I, --info            Print info about the token

This script builds off of the dirty quick way to get a token from your browser stated here: https://developer.okta.com/docs/guides/implement-oauth-for-okta/main/#get-an-access-token-and-make-a-request . This is done by opening a browser window that navigates to the
auth server with localhost as the redirect_uri. There is an http server that is spun up for just long enough to handle the redirect request and get the token from the window.hash

Implemented in another script:

fetcher = OktaToken(
    issuer="https://my-okta-org.okta.com/8a88fje02348ljajr8,
    client_id=my-oidc-app-client-id,
    final_redirect="https://github.com",
    token_type="token",
    use_keychain=True,
)
print(fetcher.token)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

okta_token_fetcher-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

okta_token_fetcher-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file okta_token_fetcher-0.1.1.tar.gz.

File metadata

  • Download URL: okta_token_fetcher-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for okta_token_fetcher-0.1.1.tar.gz
Algorithm Hash digest
SHA256 abd70a7f7cd42621743df1a7d3e2b52342dfa6eaedb7839d9eab05812cca64bc
MD5 7fe9b1890fb8188246ca93509e34cd13
BLAKE2b-256 f9d7e72738de5a1d1a175dcf03defbf45156858ead4949100cc29903103ba05d

See more details on using hashes here.

File details

Details for the file okta_token_fetcher-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for okta_token_fetcher-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 129fe3ba9ef0f01ce3b8bb2d786806a69f8b0b797db02d434b4ac923f69cfa51
MD5 7901c3882527125ad21d5b8f48c8fea9
BLAKE2b-256 0bce925850197b64444b08b30d572ffa7584d1a69b2b173b8dd09935e907492d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page