{"id":15046805,"url":"https://github.com/altostra/altostra-cli-login-auth0","last_synced_at":"2025-10-27T23:31:49.267Z","repository":{"id":57096885,"uuid":"203828191","full_name":"altostra/altostra-cli-login-auth0","owner":"altostra","description":"A library that abstracts and automates the process of logging in with Auth0 from CLI","archived":false,"fork":false,"pushed_at":"2022-11-16T11:03:30.000Z","size":38,"stargazers_count":19,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-28T23:21:14.340Z","etag":null,"topics":["auth0","cli","library","login","nodejs"],"latest_commit_sha":null,"homepage":"https://medium.com/altostra/cli-authentication-with-auth0-7c9899628a44","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/altostra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-22T15:58:38.000Z","updated_at":"2023-08-03T12:03:52.000Z","dependencies_parsed_at":"2023-01-23T10:30:14.011Z","dependency_job_id":null,"html_url":"https://github.com/altostra/altostra-cli-login-auth0","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altostra%2Faltostra-cli-login-auth0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altostra%2Faltostra-cli-login-auth0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altostra%2Faltostra-cli-login-auth0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altostra%2Faltostra-cli-login-auth0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altostra","download_url":"https://codeload.github.com/altostra/altostra-cli-login-auth0/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219860467,"owners_count":16556017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","cli","library","login","nodejs"],"created_at":"2024-09-24T20:53:36.115Z","updated_at":"2025-10-27T23:31:43.966Z","avatar_url":"https://github.com/altostra.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI login with Auth0\n\nA library that abstracts and automates the process of logging in with Auth0 from CLI.\n\n## Installation\n```sh\nnpm install @altostra/cli-login-auth0\n```\n\n## Usage\nImport the class `Auth0LoginProcessor` and create a new instance.\n```TypeScript\nimport * as path from 'path'\nimport { \n  Auth0LoginProcessor, \n  tryGetAccessToken \n} from '@altostra/cli-login-auth0'\n\nconst loginProcessor = new Auth0LoginProcessor({\n  auth0ClientId: 'your-client-id',\n  auth0Domain: 'your-domain.auth0.com',\n  auth0TokenAudience: 'target-audience',\n  auth0TokenScope: 'profile',\n  port: 42224,\n  timeout: 30000,\n  successfulLoginHtmlFile: path.resolve(__dirname, 'success.html'),\n  failedLoginHtmlFile: path.resolve(__dirname, 'failure.html')\n}, tryGetAccessToken)\n```\nThe first parameter is an object of configuration values for the login processor.\nFor details on the configuration parameters, see the [Configuration](#Configuration) section below.\n\nThe second parameter is of type:\n```TypeScript\ntype DataExtractor\u003cT\u003e = (value: unknown) =\u003e T\n```\nThe login processor uses this function at the end of a successful login process to extract the data you want from the Auth0 response.\n\nThe library comes with a few simple, but common, data extractors that you can use out of the box:\n```TypeScript\n// Get an access token from the response\ninterface AccessToken { access_token: string }\ntype tryGetAccessToken = (value: unknown) =\u003e AccessToken\n\n// Get a refresh token from the response\ninterface RefreshToken { refresh_token: string }\ntype tryGetRefreshToken = (value: unknown) =\u003e RefreshToken\n\n// Get both the access and refresh tokens from the response\ntype ComboToken = AccessToken \u0026 RefreshToken\ntype tryGetComboToken = (value: unknown) =\u003e ComboToken\n```\n\nAny of the data extracotrs above will throw an `ExtendedError` (see details below) if the requested data is not found in the response.\n\n#### The ExtendedError type\nThis is a utility type defined in the library that provides you with context specicifc errors for the login process and wraps any Auth0 errors inside of it. It extends the `Error` type.\n\n## Starting the login process\n\nNow that you have the Login Processor configured, you can start the login process by calling the method `runLoginProcess`. \n```TypeScript\ntry {\n  const result = await loginProcessor.runLoginProcess()\n\n  console.log(result)\n} catch (err) {\n  console.error('Authentication failed', err)\n}\n```\n\nWhen you run the login process, a browser will open to authenticate the user. When done, the browser will redirect to the locally running HTTP server and will open either of the pages you provided in configuration, `successfulLoginHtmlFile` or `failedLoginHtmlFile`.\n\n## Configuration\nThe class takes as parameter the configuration of your Auth0 application details as well as some additional parameters required for the library to work.\n\n### Auth0 Application Details\nYou can find the information for your Auth0 settings in your [application settings](https://manage.auth0.com/#/applications).\n\n### `auth0ClientId`\nYour application clientId in Auth0.\n\n### `auth0Domain`\nYour Auth0 domain. Usually your-account.auth0.com.\n\n### `auth0TokenAudience`\nThe target audience for the requested token.\n\n### `auth0TokenScope`\nThe target scope for the requested token.\n\n### `port`\nThe local port to listen on for a response from the Auth0 redirect.\n\n### `timeout`\nThe duration to wait for the response from Auth0 before the process fails.\n\n### `successfulLoginHtmlFile`\nPath to a local HTML file to present to the user if the login process succeeds.\n\n### `failedLoginHtmlFile`\nPath to a local HTML file to present to the user if the login process fails.\n\n## Notes\nThe library starts a local HTTP server to listen for incoming HTTP connections on the port you specify. Make sure the port you're using is not already taken by another process. Since this code will probably be running in the wild, try to pick a port that's unlikley to be in use (don't use ports lik 8080, 8181, etc.).\n\nWe recommend you set the timeout to a reasonable value to allow users to complete the log-in process on the Auth0 website. It does take some time for the browser to open, the page to load and for the users to interact with the UI, maybe even type a wong password or approve the application on their social account.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltostra%2Faltostra-cli-login-auth0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltostra%2Faltostra-cli-login-auth0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltostra%2Faltostra-cli-login-auth0/lists"}