6 Commits

Author SHA1 Message Date
René Preuß
0981a12d08 chore(release): v1.0.3 2023-02-18 18:57:25 +01:00
René Preuß
36ccf819bd Change endpoints.logout to nullable
Add redirect_uri in logout route
2023-02-18 18:56:57 +01:00
René Preuß
f2e4b5c1c9 chore(release): v1.0.2 2023-02-18 14:46:38 +01:00
René Preuß
e0c8c411a1 Fix route 2023-02-18 14:46:10 +01:00
René Preuß
15c3d43831 Add important documentation 2023-02-18 14:45:14 +01:00
René Preuß
c954054621 Change readme 2023-02-18 14:34:42 +01:00
6 changed files with 64 additions and 32 deletions

10
CHANGELOG.md Normal file
View File

@@ -0,0 +1,10 @@
# Changelog
## v1.0.3
## v1.0.2
## v1.0.0
Initial Release

View File

@@ -1,47 +1,66 @@
# @bitinflow/nuxt-oauth # @bitinflow/nuxt-oauth
[![npm version][npm-version-src]][npm-version-href] > Nuxt module for OAuth2 authentication
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
> My new Nuxt module
- [✨  Release Notes](/CHANGELOG.md) - [✨  Release Notes](/CHANGELOG.md)
<!-- - [📖 &nbsp;Documentation](https://example.com) -->
## Features ## Features
<!-- Highlight some of the features your module provide here --> - 📦 OAuth2 authentication
- ⛰ &nbsp;Foo - 📦 Supports only one OAuth2 provider
- 🚠 &nbsp;Bar - 📦 Supports only implicit flow
- 🌲 &nbsp;Baz
## Quick Setup ## Quick Setup
1. Add `my-module` dependency to your project 1. Add `@bitinflow/nuxt-oauth` dependency to your project
```bash ```bash
# Using pnpm # Using pnpm
pnpm add -D my-module pnpm add -D @bitinflow/nuxt-oauth
# Using yarn # Using yarn
yarn add --dev my-module yarn add --dev @bitinflow/nuxt-oauth
# Using npm # Using npm
npm install --save-dev my-module npm install --save-dev @bitinflow/nuxt-oauth
``` ```
2. Add `my-module` to the `modules` section of `nuxt.config.ts` 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.
```js ```js
export default defineNuxtConfig({ export default defineNuxtConfig({
modules: [ modules: [
'my-module' '@bitinflow/nuxt-oauth'
] ],
ssr: false,
// or
routeRules: {
'/account/**': { ssr: false },
'/auth/**': { ssr: false }
},
oauth: {
redirect: {
login: '/login',
logout: '/',
callback: '/login',
home: '/home'
},
endpoints: {
authorization: 'https://example.com/v1/oauth/authorization',
userInfo: `https://example.com/api/users/me`,
logout: 'https://example.com/oauth/logout'
},
clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
scope: ['user:read']
},
}) })
``` ```
That's it! You can now use My Module in your Nuxt app ✨ That's it! You can now use @bitinflow/nuxt-oauth in your Nuxt app ✨
## Development ## Development
@@ -68,13 +87,3 @@ npm run test:watch
# Release new version # Release new version
npm run release npm run release
``` ```
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/my-module
[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/my-module
[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/my-module

View File

@@ -1,6 +1,6 @@
{ {
"name": "@bitinflow/nuxt-oauth", "name": "@bitinflow/nuxt-oauth",
"version": "1.0.1", "version": "1.0.3",
"description": "Nuxt 3 OAuth Module", "description": "Nuxt 3 OAuth Module",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",

View File

@@ -1,5 +1,8 @@
export default defineNuxtConfig({ export default defineNuxtConfig({
modules: ['../src/module'], modules: ['../src/module'],
ssr: false,
oauth: { oauth: {
redirect: { redirect: {
login: '/login/', // sandbox appends / at the end of url login: '/login/', // sandbox appends / at the end of url

View File

@@ -12,7 +12,7 @@ export interface ModuleOptions {
endpoints: { endpoints: {
authorization: string, authorization: string,
userInfo: string, userInfo: string,
logout: string logout: string | null
}, },
clientId: string, clientId: string,
scope: string[] scope: string[]
@@ -28,7 +28,7 @@ const defaults: ModuleOptions = {
endpoints: { endpoints: {
authorization: 'https://accounts.bitinflow.com/oauth/authorize', authorization: 'https://accounts.bitinflow.com/oauth/authorize',
userInfo: `https://accounts.bitinflow.com/api/v3/user`, userInfo: `https://accounts.bitinflow.com/api/v3/user`,
logout: 'https://accounts.bitinflow.com/logout' logout: null,
}, },
clientId: 'please-set-client-id', clientId: 'please-set-client-id',
scope: ['user:read'] scope: ['user:read']

View File

@@ -45,7 +45,17 @@ export default async (options: ComposableOptions = {
accessToken.value = null; accessToken.value = null;
user.value = null; user.value = null;
return navigateTo('/') if (authConfig.endpoints.logout) {
// create oauth logout url
const params = new URLSearchParams({
client_id: authConfig.clientId,
redirect_uri: window.location.origin + authConfig.redirect.logout
})
window.location.href = `${authConfig.endpoints.logout}?${params.toString()}`
}
return navigateTo(authConfig.redirect.logout)
} }
const setBearer = async (token: string, tokenType: string, expires: number) => { const setBearer = async (token: string, tokenType: string, expires: number) => {