- {
- “cells”: [
- {
“cell_type”: “code”, “execution_count”: 1, “metadata”: {}, “outputs”: [], “source”: [
“import mdf_toolbox”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“# Authentication Utilitiesn”, “The MDF Toolbox contains a few different ways to easily authenticate using Globus Auth, and even automatically make certain clients for you.n”, “n”, “Note: This is not an exhaustive list of all parameters and options available. This is a basic tutorial for the most common usages.”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Interactive user login with login()n”, “The login() helper uses your own credentials to authenticate. You can specify services by name or scope as services=[“name_or_scope”] You will have to follow a link to Globus Auth the first time you use a service (your tokens will be cached after the first login). To reset your tokens, use clear_old_tokens=True.”]
}, {
“cell_type”: “code”, “execution_count”: 2, “metadata”: {
“scrolled”: false}, “outputs”: [], “source”: [
“result = mdf_toolbox.login(services=[“mdf_connect”, “transfer”])”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“Toolbox will handle connecting to Globus Auth. The return value is a dictionary, with each service you requested as a key.”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“If there is a client associated with a service, you get that client back. This feature can be turned off with make_clients=False.”]
}, {
“cell_type”: “code”, “execution_count”: 3, “metadata”: {
“scrolled”: true}, “outputs”: [
- {
- “data”: {
- “text/plain”: [
- “<globus_sdk.transfer.client.TransferClient at 0x7f2738649a58>”
]
}, “execution_count”: 3, “metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“result[“transfer”]”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“If there is no client for a service, you get a RefreshTokenAuthorizer instead.”]
}, {
“cell_type”: “code”, “execution_count”: 4, “metadata”: {}, “outputs”: [
- {
- “data”: {
- “text/plain”: [
- “<globus_sdk.authorizers.refresh_token.RefreshTokenAuthorizer at 0x7f2738649a90>”
]
}, “execution_count”: 4, “metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“result[“mdf_connect”]”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“A RefreshTokenAuthorizer allows you to authenticate a request with .set_authorization_header().”]
}, {
“cell_type”: “code”, “execution_count”: 5, “metadata”: {}, “outputs”: [], “source”: [
“headers = {}n”, “result[“mdf_connect”].set_authorization_header(headers)n”, “# requests.get(url, headers=headers)”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Programmatic client login with confidential_login()n”, “If you have a Confidential Client (registered through https://developers.globus.org/), that client can login as itself using confidential_login(). In addition to specifying services=[] as with login(), you must also provide the client_id and client_secret for your Confidential Client.”]
}, {
“cell_type”: “code”, “execution_count”: 6, “metadata”: {}, “outputs”: [], “source”: [
“client_id = “”n”, “client_secret = “””]
}, {
“cell_type”: “code”, “execution_count”: 7, “metadata”: {}, “outputs”: [], “source”: [
“result = mdf_toolbox.confidential_login(client_id=client_id,n”, ” client_secret=client_secret,n”, ” services=[“mdf_connect”, “transfer”])”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“The return value is almost the same as login() except the default authorizer is a ClientCredentialsAuthorizer (which can be used in the same way as a RefreshTokenAuthorizer. You can still disable making clients where possible by passing make_clients=False.”]
}, {
“cell_type”: “code”, “execution_count”: 8, “metadata”: {}, “outputs”: [
- {
- “data”: {
- “text/plain”: [
- “<globus_sdk.transfer.client.TransferClient at 0x7f2738684cc0>”
]
}, “execution_count”: 8, “metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“result[“transfer”]”]
}, {
“cell_type”: “code”, “execution_count”: 9, “metadata”: {}, “outputs”: [
- {
- “data”: {
- “text/plain”: [
- “<globus_sdk.authorizers.client_credentials.ClientCredentialsAuthorizer at 0x7f27386840f0>”
]
}, “execution_count”: 9, “metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“result[“mdf_connect”]”]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## No-auth client creation with anonymous_login()n”, “If you don’t want to log in with any credentials, you can use anonymous_login() to automatically create clients. The only accepted parameter is services.n”, “n”, “Note: Only clients can be returned this way. You cannot make an anonymous RefreshTokenAuthorizer. Additionally, many clients have auth-only features that will not work when not authenticated, such as initiating a transfer with a TransferClient.”]
}, {
“cell_type”: “code”, “execution_count”: 10, “metadata”: {}, “outputs”: [], “source”: [
“result = mdf_toolbox.anonymous_login(“transfer”)”]
}, {
“cell_type”: “code”, “execution_count”: 11, “metadata”: {}, “outputs”: [
- {
- “data”: {
- “text/plain”: [
- “<globus_sdk.transfer.client.TransferClient at 0x7f2738669a90>”
]
}, “execution_count”: 11, “metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“result[“transfer”]”]
}, {
“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: []}
], “metadata”: {
- “kernelspec”: {
- “display_name”: “Python 3”, “language”: “python”, “name”: “python3”
}, “language_info”: {
- “codemirror_mode”: {
- “name”: “ipython”, “version”: 3
}, “file_extension”: “.py”, “mimetype”: “text/x-python”, “name”: “python”, “nbconvert_exporter”: “python”, “pygments_lexer”: “ipython3”, “version”: “3.8.0”
}
}, “nbformat”: 4, “nbformat_minor”: 2
}