Browse Source
- add `oidc-client-ts` package - add `onlyOidc` environment variable - add oidc login and token refresh functions to `useAuthStore` - If `onlyOidc` is enabled to guide users to jump to the certification authority server - third-party login only provides certification center serverpull/1220/head
14 changed files with 196 additions and 45 deletions
@ -0,0 +1,54 @@ |
|||||
|
import { useAppConfig } from '@vben/hooks'; |
||||
|
|
||||
|
import { UserManager, WebStorageStateStore } from 'oidc-client-ts'; |
||||
|
|
||||
|
const { authority, audience, clientId, clientSecret } = useAppConfig( |
||||
|
import.meta.env, |
||||
|
import.meta.env.PROD, |
||||
|
); |
||||
|
|
||||
|
const userManager = new UserManager({ |
||||
|
authority, |
||||
|
client_id: clientId, |
||||
|
client_secret: clientSecret, |
||||
|
redirect_uri: `${window.location.origin}/signin-callback`, |
||||
|
response_type: 'code', |
||||
|
scope: audience, |
||||
|
post_logout_redirect_uri: `${window.location.origin}/`, |
||||
|
silent_redirect_uri: `${window.location.origin}/silent-renew.html`, |
||||
|
automaticSilentRenew: true, |
||||
|
loadUserInfo: true, |
||||
|
userStore: new WebStorageStateStore({ store: window.localStorage }), |
||||
|
}); |
||||
|
|
||||
|
export default { |
||||
|
async login() { |
||||
|
return userManager.signinRedirect(); |
||||
|
}, |
||||
|
|
||||
|
async logout() { |
||||
|
return userManager.signoutRedirect(); |
||||
|
}, |
||||
|
|
||||
|
async refreshToken() { |
||||
|
return userManager.signinSilent(); |
||||
|
}, |
||||
|
|
||||
|
async getAccessToken() { |
||||
|
const user = await userManager.getUser(); |
||||
|
return user?.access_token; |
||||
|
}, |
||||
|
|
||||
|
async isAuthenticated() { |
||||
|
const user = await userManager.getUser(); |
||||
|
return !!user && !user.expired; |
||||
|
}, |
||||
|
|
||||
|
async handleCallback() { |
||||
|
return userManager.signinRedirectCallback(); |
||||
|
}, |
||||
|
|
||||
|
async getUser() { |
||||
|
return userManager.getUser(); |
||||
|
}, |
||||
|
}; |
||||
@ -0,0 +1,15 @@ |
|||||
|
<script lang="ts" setup> |
||||
|
import { onMounted } from 'vue'; |
||||
|
|
||||
|
import { useAuthStore } from '#/store/auth'; |
||||
|
|
||||
|
const authStore = useAuthStore(); |
||||
|
|
||||
|
onMounted(async () => { |
||||
|
await authStore.oidcCallback(); |
||||
|
}); |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<div>{{ $t('page.auth.processingLogin') }}</div> |
||||
|
</template> |
||||
Loading…
Reference in new issue