This commit is contained in:
andrea.terzani
2025-04-17 07:38:38 +02:00
parent d14172ceb6
commit ae16bf4d7e
2 changed files with 30 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ import axios from 'axios';
import Message from 'primevue/message';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { msalInstance } from './MsalConfig';
import { msalInstance, msalrequest } from './MsalConfig';
const auth = useAuth();
const { isDarkTheme } = useLayout();
const username = ref('');
@@ -29,7 +29,7 @@ onMounted(async () => {
const loginAD = async () => {
var token = await msalInstance.acquireTokenSilent({
scopes: ["api://d3fee0e3-49e0-4910-b0b4-805bfbd5488a/access_as_user"],
scopes: msalrequest.scopes,
account: msaccount.value
})
console.log("Token " ,token)
@@ -57,9 +57,7 @@ const loginAD = async () => {
const loginMsal = async () => {
await msalInstance.initialize()
msalInstance.loginRedirect({
scopes: ["api://d3fee0e3-49e0-4910-b0b4-805bfbd5488a/access_as_user"]
})
msalInstance.loginRedirect(msalrequest)
}
const login_old = async () => {
@@ -130,20 +128,14 @@ const login_old = async () => {
<InputText id="email1" type="text" placeholder="Username" class="w-full md:w-[30rem] mb-8" style="padding: 1rem" v-model="username" />
<label for="password1" class="block text-surface-900 dark:text-surface-0 font-medium text-xl mb-2">Password</label>
<Password id="password1" v-model="password" placeholder="Password" :toggleMask="true" class="w-full mb-4" inputClass="w-full" :inputStyle="{ padding: '1rem' }"></Password>
<!--
<div class="flex items-center justify-between mb-8 gap-8">
<div class="flex items-center">
<Checkbox v-model="checked" id="rememberme1" binary class="mr-2"></Checkbox>
<label for="rememberme1">Remember me</label>
</div>
<a class="font-medium no-underline ml-2 text-right cursor-pointer" style="color: var(--primary-color)">Forgot password?</a>
<Password id="password1" v-model="password" placeholder="Password" :toggleMask="true" class="w-full md:w-[30rem] mb-8" inputClass="w-full" :inputStyle="{ padding: '1rem' }"></Password>
<div class="flex flex-col items-center">
<Button @click="login_old" label="Sign In with Username & Password" class="w-full mb-2 md:w-[30rem] text-xl" ></Button>
<Button @click="loginMsal" v-if="msaccount == null" label="Sign In with Microsoft" class="w-full mb-2 md:w-[30rem] text-xl" ></Button>
<Button @click="loginAD" v-if="msaccount" :label="'Login ' + msaccount.username " class="w-full mb-2 md:w-[30rem] text-xl"></Button>
<Message v-if="visible" severity="error" :life="3000" class="mt-2 error-message">{{ error }}</Message>
</div>
-->
<Button @click="login_old" label="Sign In with Username & Password" class="w-full p-4 text-xl mb-4" />
<Button @click="loginMsal" v-if="msaccount == null" label="Sign In with Microsoft" class="w-full p-4 text-xl" />
<Button @click="loginAD" v-if="msaccount" :label="'Login ' + msaccount.username " class="w-full p-4 text-xl" />
<Message v-if="visible" severity="error" :life="3000" class="mt-2 error-message">{{ error }}</Message>
</div>
</div>
</div>

View File

@@ -5,8 +5,8 @@ import { PublicClientApplication } from '@azure/msal-browser';
export const msalInstance = new PublicClientApplication({
auth: {
clientId: 'd3fee0e3-49e0-4910-b0b4-805bfbd5488a',
authority: "https://login.microsoftonline.com/9dc4721e-4d54-4c40-a681-1dd740292901",
clientId: '0c51b431-65ef-40fa-89ff-f66a1c583e0d',
authority: "https://login.microsoftonline.com/f3211d0e-125b-42c3-86db-322b19a65a22/",
redirectUri: "http://localhost:5173/auth/callback", // or your deployed URL
navigateToLoginRequestUrl: false,
},
@@ -16,4 +16,20 @@ export const msalInstance = new PublicClientApplication({
}
})
/*
export const msalInstance = new PublicClientApplication({
auth: {
clientId: 'd3fee0e3-49e0-4910-b0b4-805bfbd5488a',
authority: "https://login.microsoftonline.com/9dc4721e-4d54-4c40-a681-1dd740292901",
redirectUri: "http://localhost:5173/auth/callback", // or your deployed URL
navigateToLoginRequestUrl: false,
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: false,
}
})
*/
export const msalrequest = {
scopes: ["User.Read", "Mail.Read"],
}