Code Handlers

Code Handers serve as a mechanism to complete the Globus Native App Auth Flow, by ensuring that the auth code returned as the final leg of the flow is copied from the globus webapp and exchanged with Globus Auth for tokens.

Special code handlers like the LocalServerCodeHandler can copy this code automatically to streamline the auth flow. InputCodeHandler is less convenient, but can be used to manually copy the code in the case where the user is logged into a remote service.

from fair_research_login import NativeClient, InputCodeHandler, LocalServerCodeHandler

app = NativeClient(
    client_id='my-client-id',
    code_handlers=[InputCodeHandler, LocalServerCodeHandler],
)
class fair_research_login.InputCodeHandler(paste_url_in_browser_msg=None)

Bases: CodeHandler

Input Code Handler. Can be set as a code handler in a NativeClient.

class fair_research_login.LocalServerCodeHandler(template=None, template_vars=None, hostname='localhost', cli_message=None)

Bases: CodeHandler

Local Server Code Handler. Useful when using apps that run on a user machine. Used for automatically copying the auth-code to complete the native app auth flow, for added simplicity.

class fair_research_login.code_handler.CodeHandler(paste_url_in_browser_msg=None)

Bases: object

Generic handler for the code returned by the Native App Auth Flow in Globus Auth. It’s intended to be subclassed to define the behavior for how the code gets from Globus Auth to the Native App.

The primary method to override is the get_code() method, used to complete the auth flow.

static is_browser_enabled()

Will login automatically open the users browser to the Globus Auth Link? If False, the user will need to manually open a browser and copy/paste the link.

static set_browser_enabled(value)

Set whether login will automatically open the users browser to the Globus Auth Link. GLOBAL SETTING, this will affect ALL Code Handlers.

start()

An extra method to do any extra startup before calling authenticate() For local_sever, this is a time to start a thread for a local TCP server for handling the auth code. For simple handlers like the InputCodeHandler, this can be safely ignored.

is_available()

Can this code handler be used? If False, the client will skip this handler and use the next one in the list. Typically this will be used for the LocalServerCodeHandler when in an SSH session so it can abort and use a InputCodeHandler instead.

get_redirect_uri()

For use with code handlers that don’t know their redirect_uri until start() is called. For local_server, this is needed to find an open port number to return something like http://localhost:<PORT>/ Return None to use the default Globus helper page

set_context(client, **kwargs)

Set context for a given code handler, which includes the NativeClient itself and any login_kwargs.

authenticate(url)

Use the given url to direct the user to Globus Auth so they can login. :param url: URL to Globus Auth. :return:

write_message(message)

This will likely be the only place where output needs to be directly written to the user. Some CLIs like Click may prefer click.echo here rather than print. :param message: Direct Standard Output message for user consumption

get_code()

Override in child. Get the code returned by Globus Auth to complete the Native App Auth Flow. :return: Code returned by Globus Auth

is_remote_session()

Check if this is being run from an ssh shell. :return: True if ssh shell, false otherwise