0.1.7 • Published 3 years ago

vue3-linkedin-login v0.1.7

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

Vue3 Login with LinkedIn

This is a Vue3 package that provides a simple way to authenticate users with LinkedIn. It uses the LinkedIn OAuth2 protocol for user authentication and the LinkedIn API to retrieve the user's profile and other information.

Installation

npm install --save vue3-linkedin-login

We will trigger linkedInLogin by using useLinkedIn after click on Sign in with LinkedIn button, a popup window will show up and ask for the permission. After we accepted, the pop up window will redirect to redirectUri (should be LinkedInCallback component) then notice its opener about the authorization code Linked In provides us.

Usage

<template>
  <button @click="linkedInLogin">test</button>
</template>

<script setup>
  import { onMounted } from "vue";
  import { useLinkedIn, LinkedInCallback } from "vue3-linkedin-login";

  const { linkedInLogin, exchangeCodeForToken, getAccount, getMail } =
    useLinkedIn({
      clientId: "",
      clientSecret: "",
      redirectUri: "",
      onSuccess: async (code) => {
        const exchangeCode = await exchangeCodeForToken(code);
        const account = await getAccount(exchangeCode.access_token);
        const email = await getMail(exchangeCode.access_token);

        if (!account || !email) {
          return;
        }

        const firstName = account.localizedFirstName;
        const lastName = account.localizedLastName;
        const emailAddress = email.elements[0]["handle~"].emailAddress;

        const user = {
          firstName,
          lastName,
          emailAddress,
        };

        console.log(user);
      },
      scope: "r_emailaddress,r_liteprofile",
      onError: (error) => {
        console.log(error);
      },
    });

  onMounted(() => {
    LinkedInCallback();
  });
</script>

Props

ParameterValueIs RequiredDefault
clientIdstringtrue-
clientSecretstringtrue-
redirectUristringtrue-
onSuccessfunctiontrue-
onErrorfunctiontrue-
scopestringtruer_liteprofile
statestringfalse-

This repo is inspired by the https://github.com/nvh95/react-linkedin-login-oauth2/ repo.

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago