-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathLogin.vue
More file actions
51 lines (46 loc) · 1.78 KB
/
Login.vue
File metadata and controls
51 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!-- The Login component is for users to initiate the login process.
It presents a "Login" button within the toolbar menu, which, when clicked, redirects the user to the
authentication page. After successful login, the user is redirected back to the previous page. -->
<template>
<ToolbarMenu
icon="wikiglyph-user-inactive"
:tooltip="$t('login.loginMenu.tooltip')"
:translateItems="false"
:items="[{id:'login', text:itemtext}]"
@doMenuItemAction="getCode"
>
<div slot="menu-title">{{ $t('login.loginMenu.title') }}</div>
</ToolbarMenu>
</template>
<script>
import pkceChallenge from "@/pkce-challenge";
import ToolbarMenu from '@/components/menu/ToolbarMenu'
export default {
name: 'LoginButton',
data(){
return{
// This is a public app with upload and edit grant
CLIENT_ID : process.env.OAUTH_CLIENT_ID || "f2aa70edfeb48a0eb08614c69b9148b4",
itemtext: this.$t('login.loginMenu.item')
}
},
components: {
ToolbarMenu,
},
methods: {
async getCode() {
localStorage.setItem('previouspage', window.location.href);
const challenge = await pkceChallenge();
localStorage.setItem('codeVerifier', challenge.code_verifier);
const params = new URLSearchParams();
params.append("client_id", this.CLIENT_ID);
params.append("response_type", "code");
params.append("code_challenge", challenge.code_challenge);
params.append("code_challenge_method", "S256");
// Redirect the browser to the OAuth 2 login page
const url = "https://meta.wikimedia.org/w/rest.php/oauth2/authorize?" + params;
window.location.href = url;
},
}
}
</script>