{"id":20261903,"url":"https://github.com/nodesolidserver/solid-auth-client","last_synced_at":"2025-07-04T01:04:48.962Z","repository":{"id":38202650,"uuid":"92537921","full_name":"nodeSolidServer/solid-auth-client","owner":"nodeSolidServer","description":"A browser library for performing authenticated requests to Solid pods","archived":false,"fork":false,"pushed_at":"2024-01-22T15:47:13.000Z","size":8467,"stargazers_count":95,"open_issues_count":77,"forks_count":40,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-07-04T01:03:41.161Z","etag":null,"topics":["running-code"],"latest_commit_sha":null,"homepage":"https://solid.github.io/solid-auth-client/","language":"JavaScript","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/nodeSolidServer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-26T18:27:21.000Z","updated_at":"2025-04-14T17:49:06.000Z","dependencies_parsed_at":"2024-06-18T15:23:01.443Z","dependency_job_id":"7a83c896-713f-4ea1-b3e1-f01bde0e5a85","html_url":"https://github.com/nodeSolidServer/solid-auth-client","commit_stats":null,"previous_names":["solid/solid-auth-client"],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/nodeSolidServer/solid-auth-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeSolidServer%2Fsolid-auth-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeSolidServer%2Fsolid-auth-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeSolidServer%2Fsolid-auth-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeSolidServer%2Fsolid-auth-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeSolidServer","download_url":"https://codeload.github.com/nodeSolidServer/solid-auth-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeSolidServer%2Fsolid-auth-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263427305,"owners_count":23464842,"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":["running-code"],"created_at":"2024-11-14T11:27:34.847Z","updated_at":"2025-07-04T01:04:48.902Z","avatar_url":"https://github.com/nodeSolidServer.png","language":"JavaScript","readme":"# A library for reading and writing to legacy Solid pods\n\n[![Build Status](https://travis-ci.org/solid/solid-auth-client.svg?branch=master)](https://travis-ci.org/solid/solid-auth-client)\n[![Coverage Status](https://coveralls.io/repos/github/solid/solid-auth-client/badge.svg?branch=master)](https://coveralls.io/github/solid/solid-auth-client?branch=master)\n[![NPM Package](https://img.shields.io/npm/v/solid-auth-client.svg)](https://www.npmjs.com/package/solid-auth-client)\n\nThe [Solid](https://solidproject.org/) project\nallows people to use apps on the Web\nwhile storing their data in their own data pod.\n\n`solid-auth-client` is a legacy browser library\nthat allows your apps to log in and read/write data using\na [Node Solid Server](https://github.com/solid/node-solid-server/).\n\n**⚠️ New projects should use [solid-client-authn](https://github.com/inrupt/solid-client-authn-js)\nor [solid-auth-fetcher](https://github.com/solid/solid-auth-fetcher) instead,\nwhich leverage the secure DPoP authentication mechanism\nfrom the current [Solid specification](https://solid.github.io/authentication-panel/solid-oidc/),\nas implemented by [all the various Solid server implementations](https://github.com/solid/test-suite).**\n\n## Usage\nIn the browser, the library is accessible through `solid.auth`:\n```html\n\u003cscript src=\"https://solid.github.io/solid-auth-client/dist/solid-auth-client.bundle.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nsolid.auth.trackSession(session =\u003e {\n  if (!session)\n    console.log('The user is not logged in')\n  else\n    console.log(`The user is ${session.webId}`)\n})\n\u003c/script\u003e\n```\n\nWhen developing for webpack in a Node.js environment,\nrun `npm install solid-auth-client` and then do:\n\n```javascript\nconst auth = require('solid-auth-client')\n\nauth.trackSession(session =\u003e {\n  if (!session)\n    console.log('The user is not logged in')\n  else\n    console.log(`The user is ${session.webId}`)\n})\n```\n\nNote that this library is intended for the browser.\nYou can use Node.js as a development environment,\nbut not for actually logging in and out or making requests.\n\n## Functionality\nThis library offers two main types of functionality:\n- `fetch` functionality to make authenticated HTTP requests to a Solid pod\n- login and logout functionality to authenticate the user\n\n### Reading and writing data\nThe `fetch` method mimics\nthe browser's [`fetch` API]((https://fetch.spec.whatwg.org/)): \nit has the same signature and also returns a promise that resolves to the response to the request.\nYou can use it to access any kind of HTTP(S) document,\nregardless of whether that document is on a Solid pod:\n\n```javascript\nsolid.auth.fetch('https://timbl.com/timbl/Public/friends.ttl')\n  .then(console.log);\n```\n\n```javascript\nconst { fetch } = solid.auth;\nfetch('https://timbl.com/timbl/Public/friends.ttl')\n  .then(console.log);\n```\n\nIf the document is on a Solid pod,\nand the user is logged in,\nthey will be able to access private documents\nthat require read or write permissions.\n\n### Logging in\nSince Solid is decentralized,\nusers can have an account on any server.\nTherefore, users need to pick their identity provider (IDP)\nin order to log in.\n\nIf your application asks them\nfor the URL of their identity provider,\nthen you can call the `login` method with the IDP as an argument:\n```javascript\nasync function login(idp) {\n  const session = await solid.auth.currentSession();\n  if (!session)\n    await solid.auth.login(idp);\n  else\n    alert(`Logged in as ${session.webId}`);\n}\nlogin('https://solidcommunity.net');\n```\nBe aware that this will _redirect_ the user away from your application\nto their identity provider.\nWhen they return, `currentSession()` will return their login information.\n\nIf you want `solid-auth-client` to ask the user for their identity provider,\nthen you can use a popup window:\n```javascript\nasync function popupLogin() {\n  let session = await solid.auth.currentSession();\n  let popupUri = 'https://solidcommunity.net/common/popup.html';\n  if (!session)\n    session = await solid.auth.popupLogin({ popupUri });\n  alert(`Logged in as ${session.webId}`);\n}\npopupLogin();\n```\nThe popup has the additional benefit\nthat users are not redirected away.\n\nYou can find a popup in `dist-popup/popup.html`.\n\n### Logging out\nTo log out, simply call the `logout` method:\n```javascript\nsolid.auth.logout()\n  .then(() =\u003e alert('Goodbye!'));\n```\n\n### Getting the current user\nThe current user is available through the `currentSession` method.\nThis returns a session, with the `webId` field indicating the user's WebID.\n\n```javascript\nasync function greetUser() {\n  const session = await solid.auth.currentSession();\n  if (!session)\n    alert('Hello stranger!');\n  else\n    alert(`Hello ${session.webId}!`);\n}\ngreetUser();\n```\n\nIf you want to track user login and logout,\nuse the `trackSession` method instead.\nIt will invoke the callback with the current session,\nand notify you of any changes to the login status.\n\n```javascript\nsolid.auth.trackSession(session =\u003e {\n  if (!session)\n    alert('Hello stranger!');\n  else\n    alert(`Hello ${session.webId}!`);\n});\n```\n\n### Events\n\n`SolidAuthClient` implements [`EventEmitter`](https://nodejs.org/api/events.html)\nand emits the following events:\n- `login (session: Session)` when a user logs in\n- `logout ()` when a user logs out\n- `session (session: Session | null)` when a user logs in or out\n\n### Client registration\n\n`SolidAuthClient` automatically registers your OIDC client application if it is\nunknown to the authorization server, following\n[the registration request spec](https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest).\n\nYou can specify some fields of this registration request by passing them to the\n`loginSession` parameter of `solid.auth.login`.\n\nSupported fields are:\n\n*  `client_name` and internationalized variants (`clientName` property)\n* `contacts` (`contacts` property)\n* `logo_uri` (`logoUri` property)\n\n**Example**:\n\n```js\nsolid.auth.login(idp, {\n    clientName: 'My Example',\n    'clientName#ja-Jpan-JP': 'クライアント名',\n    logoUri: 'https://client.example.org/logo.png',\n    contacts: ['ve7jtb@example.org', 'mary@example.org']\n})\n````\n\n## Advanced usage\n\n### Generating a popup window\nTo log in with a popup window, you'll need a popup application running on a\ntrusted domain which authenticates the user, handles redirects, and messages\nthe authenticated session back to your application.\n\nIn order to tell the user they're logging into *your* app, you'll need to\ngenerate a static popup bound to your application's name.\n\n0. Make sure you've got the `solid-auth-client` package installed globally.\n```sh\n$ npm install -g solid-auth-client # [--save | --save-dev]\n```\n\n1. Run the generation script to generate the popup's HTML file.\n```sh\n$ solid-auth-client generate-popup # [\"My App Name\"] [my-app-popup.html]\n```\n\n2. Place the popup file on your server (say at `https://localhost:8080/popup.html`).\n\n3. From within your own app, call `solid.auth.popupLogin({ popupUri: 'https://localhost:8080/popup.html' })`.\n\n\n## Developing `solid-auth-client`\nDeveloping this library requires [Node.js](https://nodejs.org/en/) \u003e= v10.0.\n\n### Setting up the development environment\n\n```sh\n$ git clone https://github.com/solid/solid-auth-client.git\n$ cd solid-auth-client\n$ npm install\n$ npm run test     # run the code formatter, linter, and test suite\n$ npm run test:dev # just run the tests in watch mode\n```\n\n### Demo app\n\nYou can test how `solid-auth-client` operates within an app by running the demo app.\n\n#### Running the demo development server\n\n```sh\n$ POPUP_URI='http://localhost:8606/popup-template.html' npm run start:demo\n```\n\n#### Running the popup development server\n\n```sh\n$ APP_NAME='solid-auth-client demo' npm run start:popup\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesolidserver%2Fsolid-auth-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodesolidserver%2Fsolid-auth-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesolidserver%2Fsolid-auth-client/lists"}