From e8a8b296dff09d64e4fdcbe356b4ca22aba10ea0 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Wed, 29 Nov 2023 11:15:51 -0500 Subject: [PATCH] Adding geneweaver client login tutorial --- docs/tutorial/geneweaver_client_login.ipynb | 272 ++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 273 insertions(+) create mode 100644 docs/tutorial/geneweaver_client_login.ipynb diff --git a/docs/tutorial/geneweaver_client_login.ipynb b/docs/tutorial/geneweaver_client_login.ipynb new file mode 100644 index 0000000..aa06c09 --- /dev/null +++ b/docs/tutorial/geneweaver_client_login.ipynb @@ -0,0 +1,272 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Client Login\n", + "\n", + "The following tutorial will demonstrate how to use the Geneweaver Client package to log\n", + "in to the Geneweaver API. This will allow you to access the Geneweaver API from the\n", + "command line or from within a Python script.\n", + "\n", + "The Geneweaver Client (`geneweaver-client`) package is available on PyPI and can be\n", + "installed with pip or poetry. The package provides many useful functions for interacting\n", + "with Geneweaver from a client context, including utility functions to make\n", + "authentication simple.\n", + "\n", + "This tutorial will demonstrate these utility functions from a Jupyter Notebook, but they\n", + "can also be used from the command line or from within a Python script.\n", + "\n", + "\n", + "###Install the `geneweaver-client` package" + ], + "metadata": { + "id": "qXfFhL8myKJd" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Hs7pLPIhx7fE" + }, + "outputs": [], + "source": [ + "!pip install geneweaver-client" + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Using The Command Line Client\n", + "### Access Help Documentation" + ], + "metadata": { + "id": "HIBxnwBPyWwc" + } + }, + { + "cell_type": "code", + "source": [ + "!gweave beta auth --help" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "5mrdO2jjx-LQ", + "outputId": "45579f02-5f98-4657-fd8b-16b6c45da569" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001B[1m \u001B[0m\n", + "\u001B[1m \u001B[0m\u001B[1;33mUsage: \u001B[0m\u001B[1mgweave beta auth [OPTIONS] COMMAND [ARGS]...\u001B[0m\u001B[1m \u001B[0m\u001B[1m \u001B[0m\n", + "\u001B[1m \u001B[0m\n", + " The auth commands allow you to authenticate with the GeneWeaver API. \n", + " \n", + "\u001B[2m╭─\u001B[0m\u001B[2m Options \u001B[0m\u001B[2m───────────────────────────────────────────────────────────────────────\u001B[0m\u001B[2m─╮\u001B[0m\n", + "\u001B[2m│\u001B[0m \u001B[1;36m-\u001B[0m\u001B[1;36m-help\u001B[0m Show this message and exit. \u001B[2m│\u001B[0m\n", + "\u001B[2m╰──────────────────────────────────────────────────────────────────────────────────╯\u001B[0m\n", + "\u001B[2m╭─\u001B[0m\u001B[2m Commands \u001B[0m\u001B[2m──────────────────────────────────────────────────────────────────────\u001B[0m\u001B[2m─╮\u001B[0m\n", + "\u001B[2m│\u001B[0m \u001B[1;36mlogin \u001B[0m\u001B[1;36m \u001B[0m Run the device authorization flow. \u001B[2m│\u001B[0m\n", + "\u001B[2m│\u001B[0m \u001B[1;36mprint-access-token \u001B[0m\u001B[1;36m \u001B[0m Print the current user's access token. \u001B[2m│\u001B[0m\n", + "\u001B[2m│\u001B[0m \u001B[1;36mprint-identity-token \u001B[0m\u001B[1;36m \u001B[0m Print the current user's identity token. \u001B[2m│\u001B[0m\n", + "\u001B[2m╰──────────────────────────────────────────────────────────────────────────────────╯\u001B[0m\n", + "\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### Login To Geneweaver" + ], + "metadata": { + "id": "U2Xelf5Xyk1x" + } + }, + { + "cell_type": "code", + "source": [ + "!gweave beta auth login" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "IDPInF0WyhGf", + "outputId": "53bad9b8-e0c8-458d-ecd2-9d056859f400" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1. On your computer or mobile device navigate to: https://geneweaver.auth0.com/activate?user_code=PNTH-VVCC\n", + "2. Enter the following code: PNTH-VVCC\n", + "Authenticated!\n", + "- Id Token: eyJhbGciOi...\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!gweave beta auth print-access-token" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "nuOAds5gyqqY", + "outputId": "32c37920-daff-4547-c62b-84a902191944" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "eyJhbGciOiJSUzI1...\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!gweave beta auth print-identity-token" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "x62YK2twzR8J", + "outputId": "51f064f2-811b-4743-f6b1-b42c636f5241" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "eyJhbGciOiJSUzI1...\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Using The Python Package\n", + "### Login To Geneweaver" + ], + "metadata": { + "id": "vZf6SfxrzZMX" + } + }, + { + "cell_type": "code", + "source": [ + "from geneweaver.client.auth import login" + ], + "metadata": { + "id": "wQWHglhJzha6" + }, + "execution_count": 7, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Run the login function and follow the link in the output.\n", + "# Confirm that the code matches the output here,\n", + "# then sign-up or login.\n", + "login()\n", + "# Wait for the \"Authenticated!\" message, then continue." + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "f_8mne96zt8d", + "outputId": "469ffac6-a789-41e7-b6f2-18547b31628e" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1. On your computer or mobile device navigate to: https://geneweaver.auth0.com/activate?user_code=RNPC-MKQJ\n", + "2. Enter the following code: RNPC-MKQJ\n", + "Authenticated!\n", + "- Id Token: eyJhbGciOi...\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from geneweaver.client.auth import get_access_token" + ], + "metadata": { + "id": "8knTLojQzxIs" + }, + "execution_count": 12, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "get_access_token()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 105 + }, + "id": "2SSTSFVkz1EF", + "outputId": "756d5123-45fa-47c9-b471-1f3734df3ba9" + }, + "execution_count": 13, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'eyJhbGciOiJSUzI1N...'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 13 + } + ] + } + ] +} diff --git a/mkdocs.yml b/mkdocs.yml index 77d7db3..08b54d2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -79,6 +79,7 @@ nav: - Package Based Architecture: concepts/package-based-architecture.md - Tutorial: - tutorial/index.md + - Client Login: tutorial/geneweaver_client_login.ipynb - NCI-60 Example Workflow: tutorial/nci_60_example_01.ipynb - Download Genesets: tutorial/download_genesets.ipynb # - Accessing Geneweaver Data: tutorial/accessing-geneweaver-data.md