mirror of
https://github.com/bitinflow/nuxt-oauth.git
synced 2026-03-13 13:45:59 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0981a12d08 | ||
|
|
36ccf819bd | ||
|
|
f2e4b5c1c9 | ||
|
|
e0c8c411a1 | ||
|
|
15c3d43831 | ||
|
|
c954054621 |
10
CHANGELOG.md
Normal file
10
CHANGELOG.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
|
||||
## v1.0.3
|
||||
|
||||
## v1.0.2
|
||||
|
||||
## v1.0.0
|
||||
|
||||
Initial Release
|
||||
65
README.md
65
README.md
@@ -1,47 +1,66 @@
|
||||
# @bitinflow/nuxt-oauth
|
||||
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![License][license-src]][license-href]
|
||||
|
||||
> My new Nuxt module
|
||||
> Nuxt module for OAuth2 authentication
|
||||
|
||||
- [✨ Release Notes](/CHANGELOG.md)
|
||||
<!-- - [📖 Documentation](https://example.com) -->
|
||||
|
||||
## Features
|
||||
|
||||
<!-- Highlight some of the features your module provide here -->
|
||||
- ⛰ Foo
|
||||
- 🚠 Bar
|
||||
- 🌲 Baz
|
||||
- 📦 OAuth2 authentication
|
||||
- 📦 Supports only one OAuth2 provider
|
||||
- 📦 Supports only implicit flow
|
||||
|
||||
## Quick Setup
|
||||
|
||||
1. Add `my-module` dependency to your project
|
||||
1. Add `@bitinflow/nuxt-oauth` dependency to your project
|
||||
|
||||
```bash
|
||||
# Using pnpm
|
||||
pnpm add -D my-module
|
||||
pnpm add -D @bitinflow/nuxt-oauth
|
||||
|
||||
# Using yarn
|
||||
yarn add --dev my-module
|
||||
yarn add --dev @bitinflow/nuxt-oauth
|
||||
|
||||
# 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
|
||||
export default defineNuxtConfig({
|
||||
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
|
||||
|
||||
@@ -68,13 +87,3 @@ npm run test:watch
|
||||
# Release new version
|
||||
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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bitinflow/nuxt-oauth",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.3",
|
||||
"description": "Nuxt 3 OAuth Module",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
export default defineNuxtConfig({
|
||||
modules: ['../src/module'],
|
||||
|
||||
ssr: false,
|
||||
|
||||
oauth: {
|
||||
redirect: {
|
||||
login: '/login/', // sandbox appends / at the end of url
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface ModuleOptions {
|
||||
endpoints: {
|
||||
authorization: string,
|
||||
userInfo: string,
|
||||
logout: string
|
||||
logout: string | null
|
||||
},
|
||||
clientId: string,
|
||||
scope: string[]
|
||||
@@ -28,7 +28,7 @@ const defaults: ModuleOptions = {
|
||||
endpoints: {
|
||||
authorization: 'https://accounts.bitinflow.com/oauth/authorize',
|
||||
userInfo: `https://accounts.bitinflow.com/api/v3/user`,
|
||||
logout: 'https://accounts.bitinflow.com/logout'
|
||||
logout: null,
|
||||
},
|
||||
clientId: 'please-set-client-id',
|
||||
scope: ['user:read']
|
||||
|
||||
@@ -45,7 +45,17 @@ export default async (options: ComposableOptions = {
|
||||
accessToken.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) => {
|
||||
|
||||
Reference in New Issue
Block a user