{"id":13506526,"url":"https://github.com/SohoHouse/nuxt-oauth","last_synced_at":"2025-03-30T03:30:55.423Z","repository":{"id":24747902,"uuid":"101448498","full_name":"SohoHouse/nuxt-oauth","owner":"SohoHouse","description":"Simple OAuth2 integration for your Nuxt app","archived":false,"fork":false,"pushed_at":"2024-10-12T15:34:26.000Z","size":690,"stargazers_count":124,"open_issues_count":29,"forks_count":27,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-03-18T10:49:16.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/SohoHouse.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-25T23:06:03.000Z","updated_at":"2024-12-04T22:26:34.000Z","dependencies_parsed_at":"2024-04-22T17:43:16.748Z","dependency_job_id":null,"html_url":"https://github.com/SohoHouse/nuxt-oauth","commit_stats":{"total_commits":112,"total_committers":13,"mean_commits":8.615384615384615,"dds":0.6339285714285714,"last_synced_commit":"a032ea486594aaccb3028292ccd76e9d261565c9"},"previous_names":["samtgarson/nuxt-oauth"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SohoHouse%2Fnuxt-oauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SohoHouse%2Fnuxt-oauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SohoHouse%2Fnuxt-oauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SohoHouse%2Fnuxt-oauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SohoHouse","download_url":"https://codeload.github.com/SohoHouse/nuxt-oauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246273533,"owners_count":20750904,"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":[],"created_at":"2024-08-01T01:00:53.237Z","updated_at":"2025-03-30T03:30:50.414Z","avatar_url":"https://github.com/SohoHouse.png","language":"JavaScript","readme":"![nuxt-oauth](https://raw.githubusercontent.com/feathericons/feather/master/icons/lock.svg?sanitize=true)\n\n**nuxt-oauth** Simple OAuth2 integration for your Nuxt app\n\n[![CircleCI](https://circleci.com/gh/SohoHouse/nuxt-oauth.svg?style=svg)](https://circleci.com/gh/SohoHouse/nuxt-oauth)\n\n- [Usage](#usage)\n  - [Requirements](#requirements)\n  - [Get Setup](#get-setup)\n  - [Use in your application](#use-in-your-application)\n  - [Configuration](#configuration)\n    - [Dynamic Configuration](##dynamic-configuration)\n  - [Helpers](#helpers)\n  - [With your tests](#with-your-tests)\n- [Develop](#develop)\n  - [Contributing](#contributing)\n  - [Thanks](#thanks)\n  - [License](#license)\n\n## Usage\n\n### Requirements\n\n- [Nuxt](https://nuxtjs.org/)\n- Universal deployment (i.e. a [server rendered app](https://nuxtjs.org/guide#server-rendered-universal-ssr-), not an [SPA](https://nuxtjs.org/guide#single-page-applications-spa-))\n- a [Vuex store](https://nuxtjs.org/guide/vuex-store)\n\n### Get Setup\n\n1. Install the dependency:\n```bash\nyarn add nuxt-oauth\n```\n\n2. Add to your `nuxt.config.js` and configure:\n```js\n// nuxt.config.js\n\nmodules: ['nuxt-oauth'],\noauth: {\n  sessionName: 'mySession',\n  secretKey: process.env.SECRET_KEY,\n  oauthHost: process.env.OAUTH_HOST,\n  oauthClientID: process.env.OAUTH_CLIENT_ID,\n  oauthClientSecret: process.env.OAUTH_CLIENT_SECRET,\n  onLogout: (req, res) =\u003e {\n    // do something after logging out\n  },\n  fetchUser: (accessToken, request) =\u003e {\n    // do something to return the user\n    const user = User.findByToken(accessToken, request)\n    return user\n  }\n}\n```\n\n\n### Use in your application\n\n- Use the access token as you'd like from the Vuex store:\n```js\n// any-component.vue\n\nexport default {\n  mounted () {\n    const { accessToken, expires } = this.$store.state.oauth\n    // fetch more details from somewhere...\n  }\n}\n```\n\n- Mark your authenticated page components (`nuxt-oauth` will ensure users are logged in before accessing these pages):\n```js\n// secret.vue\n\nexport default {\n  authenticated: true,\n  name: 'MySecretComponent'\n}\n```\n\n### Configuration\n\n| Option | Required? | Description |\n| :----- | :-------- | :---------- |\n| `sessionName` | * | Configure the name of the cookie that nuxt-oauth uses |\n| `secretKey` | * | Provide a secret key to sign the encrypted cookie. Do not leak this! |\n| `oauthHost` | * | Host of your OAuth provider _(usually ending in `oauth` or `oauth2`)_. _Can be string or function receiving args `(req)`_ |\n| `oauthClientID` | * | Client ID of your application, registered with your OAuth provider. _Can be string or function receiving args `(req)`_ |\n| `oauthClientSecret` | * | Client ID of your application, registered with your OAuth provider. _Can be string or function receiving args `(req)`_ |\n| `scopes` |  | An array of scopes to authenticate against |\n| `authorizationPath` |  | The path to redirect users to authenticate _(defaults to `/authorize`)_ |\n| `accessTokenPath` |  | The path to request the access token _(defaults to `/token`)_ |\n| `moduleName` |  | The name of the vuex module to be created by nuxt-oauth. _(defaults to `oauth`)_ |\n| `sessionDuration` |  | The duration of the login session. _(defaults to 24 hours)_ |\n| `onLogout` | | Optional hook which is called after logging out. E.g. can be used to perform a full log out on your OAuth provider. _Receives args `(req, res, redirectUrl)`.  Can be asynchronous (or return a promise)._ |\n| `fetchUser` | | Optional hook which is called when logging in to fetch your user object. _Receives args `(accessToken, request, options)`._ |\n| `testMode` | | Flag which tells the module to ignore the OAuth dance and log every one in _(see [here](#with-your-tests) for more)_. |\n| `pageComponentPath` | | Optional page component path to replace the default page provided by this library. |\n\n#### Dynamic Configuration\n\nTo dynamically set configuration at runtime, `oauthHost`, `oauthClientID`, `oauthClientSecret` can be strings but also can be `async` functions which accept `req` as their only argument. This can be useful to choose configuration based on the URL or headers of the request.\n\n### Helpers\n\nYou can also use the functionality manually. `nuxt-oauth` injects the following helpers into your store, components and `ctx.app`: **`$login`** and **`$logout`**. Use these to manually log your user in or out.\n\nFollowing a successful login/logout, your user will be redirected back to the page from which the helper was called (you can pass a `redirectUrl` to the helpers to override this). For a full example, see below.\n\n```html\n\u003c!-- any-component.vue --\u003e\n\n\u003ctemplate\u003e\n  \u003ca @click=\"logout\" v-if=\"loggedIn\"\u003eLog Out\u003c/a\u003e\n  \u003ca @click=\"login\" v-else\u003eLog In\u003c/a\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\n  export default {\n    asyncData({ app }) {\n      // Use from context\n      app.$login()\n    }\n    computed () {\n      loggedIn () {\n        return this.$store.state.oauth.accessToken\n      }\n    },\n    methods: {\n      login () {\n        // defaults to redirecting back to the current page\n        this.$login()\n      },\n      logout () {\n        // customise the redirrect url\n        const redirectUrl = '/my-target-path'\n        this.$logout(redirectUrl)\n      }\n    }\n  }\n\u003c/script\u003e\n```\n\n### With your tests\n\nSet `options.oauth.testMode` to `true` to tell the module to skip authentication. Using this, along with the `fetchUser` option, can be helpful in e2e tests to stub your test users.\n\n## Develop\n\n```bash\ngit clone git@github.com:SohoHouse/nuxt-oauth.git\ncd nuxt-oauth\nyarn\nyarn test\n\n# To use while developing other apps:\nyarn link\ncd ../my-other-app\nyarn link nuxt-oauth\n```\n\n### Running locally\n\nTo run the fixture Nuxt app (`/test/e2e/fixture`) locally, make sure to:\n```bash\ncp .env.example .env\n```\nand populate with your real values. Then, run:\n```\nyarn dev\n```\nTo boot the app locally.\n\n### Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/SohoHouse/nuxt-oauth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n### Thanks\n\n- Many thanks to [Evan You](https://github.com/yyx990803) and the [VueJS](https://github.com/vuejs) team for sustaining such a vibrant and supportive community around Vue JS\n- Many thanks also [Alex Chopin](https://github.com/alexchopin), [Sébastien Chopin](https://github.com/Atinux), [Pooya Parsa](https://github.com/pi0) and the other [Nuxt](https://github.com/nuxt) contributors for creating this awesome library\n\n### License\n\nThe module is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Uncategorized","JavaScript"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSohoHouse%2Fnuxt-oauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSohoHouse%2Fnuxt-oauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSohoHouse%2Fnuxt-oauth/lists"}