suicide11
suicide11

Reputation: 57

Sign In with Linkedin using OpenID connect

I need to create a post using linkedIn API where I wanted to tag a person. I didn't want user to enter profile name instead authenticate them using linkedIn oauth. To tag a person I need URN of the user. Using OpenID I am only able to retrieve

{
    "sub": "782bbtaQ",
    "name": "John Doe",
    "given_name": "John",
    "family_name": "Doe",
    "picture": "https://media.licdn-ei.com/dms/image/C5F03AQHqK8v7tB1HCQ/profile-displayphoto-shrink_100_100/0/",
    "locale": "en-US",
    "email": "[email protected]",
    "email_verified": true
}

When I try calling v2/me api it throws 403. So is their any way to fetch user profile name and URN using the access token we get when user logs in.

I tried to get data from below api but I was getting 403.

try {
      const response = await axios.get("https://api.linkedin.com/v2/me", {
        headers: {
          Authorization: `Bearer ${accessToken}`,
          "X-Restli-Protocol-Version": "2.0.0",
        },
      });

      console.log("User Profile Data:", response.data);
    } catch (error) {
      console.error("Error fetching profile:", error.response?.data || error.message);
    }

Below you can find the screenshot of scopes available in auth enter image description here

Upvotes: 0

Views: 49

Answers (2)

Vadim Ostafiychuk
Vadim Ostafiychuk

Reputation: 1

try:

GET https://api.linkedin.com/v2/userinfo Authorization: Bearer

Upvotes: 0

Simone Chiari
Simone Chiari

Reputation: 1

If you want your Urn you have to use the "sub" field, for example: urn:li:person:782bbtaQ

Upvotes: 0

Related Questions