Skip to main content

This is an experimental and unsupported toolkit to help developers build Action Providers for use in Globus Automate Flows.

As this is experimental, no support is implied or provided for any sort of use of this package. It is published for ease of distribution among those planning to use it for its intended, experimental, purpose.

Toolkit Components

This toolkit provides two main components:

  1. Authentication helpers that make it easier to validate Globus Auth tokens and determine if a given request should be authorized

  2. An OpenAPI v3 specification and associated helpers that can be used to validate incoming requests and verify the responses your Action Provider generates. This document also defines the interface which must be supported by your REST API to have it function as an Action Provider.

Installation

Installation is via PyPi using, for example: pip install globus-action-provider-tools.

Usage

Authentication

The authentication helpers can be used in your action provider as follows:

from globus_action_provider_tools.authentication import TokenChecker
# You will need to register a client and scope(s) in Globus Auth
# Then initialize a TokenChecker instance for your provider:
checker = TokenChecker(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    expected_scopes=['https://auth.globus.org/scopes/YOUR_SCOPES_HERE'],
    expected_audience='YOUR_CLIENT_NAME',
)

(expected_audience should be unnecessary in the near future)

When a request comes in, use your TokenChecker to validate the access token from the HTTP Authorization header.

access_token = request.headers['Authorization'].replace('Bearer ', '')
auth_state = checker.check_token(access_token)

The AuthState has several properties and methods that will make it easier for you to decide whether or not to allow a request to proceed:

# This user's Globus identities:
auth_state.identities
# frozenset({'urn:globus:auth:identity:9d437146-f150-42c2-be88-9d625d9e7cf9',
#           'urn:globus:auth:identity:c38f015b-8ad9-4004-9160-754b309b5b33',
#           'urn:globus:auth:identity:ffb5652b-d418-4849-9b57-556656706970'})
# Groups this user is a member of:
auth_state.groups
# frozenset({'urn:globus:groups:id:606dbaa9-3d57-44b8-a33e-422a9de0c712',
#           'urn:globus:groups:id:d2ff42bc-c708-460f-9e9b-b535c3776bdd'})

You’ll notice that both groups and identities are represented as strings that unambiguously signal what type of entity they represent. This makes it easy to merge the two sets without conflict, for situations where you’d like to work with a single set containing all authentications:

all_principals = auth_state.identities.union(auth_state.groups)

The AuthState object also offers a helper method, check_authorization() that is designed to help you test whether a request should be authorized:

resource_allows = ['urn:globus:auth:identity:c38f015b-8ad9-4004-9160-754b309b5b33']
auth_state.check_authorization(resource_allows)
# True

This method also accepts two special string values, 'public' and 'all_authenticated_users', together with keyword arguments that enable their use:

 resource_allows = ['public']
 auth_state.check_authorization(resource_allows, allow_public=True)
 # True
 resource_allows = ['all_authenticated_users']
 auth_state.check_authorization(resource_allows, allow_all_authenticated_users=True)
# True

Caching

To avoid excessively taxing Globus Auth, the AuthState will, by default, cache identities and group memberships for 30 seconds.

The cache is initialized when you first instantiate your TokenChecker(). You should only need to create one TokenChecker instance for your application, and then you can re-use it to check each new token. If you do try to make multiple instances, you may get an exception:

> dogpile.cache.exception.RegionAlreadyConfigured: This region is already configured

because it’s trying to re-initialize a cache that’s already been set up.

Validation

There is an OpenAPI v3 specification for the Action Provider API available as described above. You can use any tools that accept OpenAPI v3 to validate requests to and responses from your service, but this toolkit offers some pre-configured validators using the openapi-core library.

from globus_action_provider_tools.validation import request_validator, response_validator
# Validating a request
result = request_validator.validate(request)
# Or a response:
result = response_validator.validate(request, response)
# raise errors if invalid
result.raise_for_errors()
# or get list of errors
errors = result.errors

Note that the request and response objects passed to the validators must conform to the BaseOpenAPI request and response interfaces. If you’re using Flask, you can use the provided wrappers, but if you’re using a different web framework, you’ll need to write your own small wrapper class.

Metadata

Release files for globus-action-provider-tools 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for globus-action-provider-tools 0.6
File Size Uploaded
globus-action-provider-tools-0.6.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for globus-action-provider-tools 0.6
File Interpreter ABI Platform
globus_action_provider_tools-0.6-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / globus-action-provider-tools-0.6.tar.gz

Download URL globus-action-provider-tools-0.6.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e44830920a82415c80ab77ef1146d7c6207ea798a044e9e858049fe8afb2ddb9
BLAKE2b-256 checksum
How to use checksums
9646e6e803e09fc0f096dc71abc07a410ca1fc60839d2c0ae550a4b21941f0a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-54-generic

Release files / globus_action_provider_tools-0.6-py3-none-any.whl

Download URL globus_action_provider_tools-0.6-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1351cac32b3247fa5ccb5bb7e9ba39f9341371ad9152a5d4fd195a42bb8a4c7
BLAKE2b-256 checksum
How to use checksums
a67f9c45ffd1029347adc429d3f3c70dce5f7b2adf1c9ce88d0f012421b88cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-54-generic

Release history Release notifications | RSS feed

0.21.0

2 release files

0.19.1

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.11.5

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.5

2 release files

0.10.4

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

This release

0.6 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page