From 4b7d11f44dd58ab052cdd4901067056f2e1927c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Sat, 8 Apr 2023 16:07:39 +0200 Subject: [PATCH] Update documentation Fix typo --- README.md | 51 +++++++++++++++++++++++++++++++++++++-------------- src/module.ts | 2 +- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e4102a9..22d449b 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,28 @@ # 🔒 @bitinflow/nuxt-oauth -**@bitinflow/nuxt-oauth** is a Nuxt 3 Module that provides a simple OAuth 2 implementation for static site nuxt applications. It uses an Implicit Grant where no backend code is required, and plans to support PKCE as well. This package is intended to be used with laravel-passport, allowing users to interact with their first-party API using their own OAuth provider. Currently, it does not support multiple OAuth providers. With **@bitinflow/nuxt-oauth**, developers can quickly and easily implement secure OAuth authentication in their Nuxt applications. +**@bitinflow/nuxt-oauth** is a Nuxt 3 Module that provides a simple OAuth 2 implementation for static site nuxt +applications for which no backend code is required. It uses the recommended Authorization Code Grant with PKCE by +default and supports Implicit Grant Tokens as well. + +This package is intended to be used with Laravel Passport, allowing users to interact with their first-party API using +their own OAuth provider. Currently, it does not support multiple OAuth providers. With **@bitinflow/nuxt-oauth**, +developers can quickly and easily implement secure OAuth authentication in their Nuxt applications. - [✨  Release Notes](/CHANGELOG.md) ## Features - 📦 Authorization Code Grant with PKCE (default) -- 📦 Simple OAuth 2 Implicit Grant authentication ([not recommended](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)) +- 📦 Simple OAuth 2 Implicit Grant Token + authentication ([not recommended](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)) - 📦 Intended to be used with laravel-passport - 📦 Single OAuth provider support (currently) ## Quick Setup +> **Note:** Starting with **@bitinflow/nuxt-oauth** v1.2.0, the default response type is `code`. If you want to use the +> `token` response type, you need to set it explicitly in the configuration. + 1. Add `@bitinflow/nuxt-oauth` dependency to your project ```bash @@ -27,8 +37,9 @@ npm install --save-dev @bitinflow/nuxt-oauth ``` 2. Add `@bitinflow/nuxt-oauth` to the `modules` section of `nuxt.config.ts` and disable `ssr`. - -Or alternatively disable `ssr` via `routeRules`, only for pages where `auth` or `guest` middlewares are needed. Typically account section and login page. + +Or alternatively disable `ssr` via `routeRules`, only for pages where `auth` or `guest` middlewares are needed. +Typically account section and login page. ```js export default defineNuxtConfig({ @@ -39,28 +50,40 @@ export default defineNuxtConfig({ ssr: false, // or routeRules: { - '/account/**': { ssr: false }, - '/auth/**': { ssr: false } + '/account/**': {ssr: false}, + '/auth/**': {ssr: false} }, + // using code response type (default) oauth: { - redirect: { - login: '/login', - logout: '/', - callback: '/login', - home: '/home' - }, endpoints: { - authorization: 'https://example.com/v1/oauth/authorization', - userInfo: `https://example.com/api/users/me`, + authorization: 'https://example.com/oauth/authorize', + token: 'https://example.com/oauth/token', + userInfo: 'https://example.com/api/users/me', logout: 'https://example.com/oauth/logout' }, clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', scope: ['user:read'] }, + + // using token response type (not recommended) + oauth: { + endpoints: { + authorization: 'https://example.com/oauth/authorize', + userInfo: 'https://example.com/api/users/me', + logout: 'https://example.com/oauth/logout' + }, + clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', + responseType: 'token', + scope: ['user:read'] + }, }) ``` +This will be your callback url (host is determined by `window.location.origin`): + +- Callback: `http://localhost:3000/login` + That's it! You can now use @bitinflow/nuxt-oauth in your Nuxt app ✨ ## Development diff --git a/src/module.ts b/src/module.ts index 6729fe6..7b5a34c 100644 --- a/src/module.ts +++ b/src/module.ts @@ -34,7 +34,7 @@ const defaults: ModuleOptions = { endpoints: { authorization: 'https://accounts.bitinflow.com/oauth/authorize', token: 'https://accounts.bitinflow.com/oauth/token', - userInfo: `https://accounts.bitinflow.com/api/v3/user`, + userInfo: 'https://accounts.bitinflow.com/api/v3/user', logout: null, }, refreshToken: {