0

I have created a chrome plugin to fetch the list of user, I am using Octokit

chrome.runtime.onMessage.addListener(getDataFromPopup);
function getDataFromPopup(message){
    const apiUrl = message.apiUrl;
    const apiToken = message.apiToken;

    console.log('apiToken -> '+apiToken);
    console.log('apiUrl -> '+apiUrl);
    const objOctokit = new Octokit({
        auth: 'token '+apiToken,
        // set custom URL for on-premise GitHub Enterprise installations
        baseUrl: apiUrl,
        request: {
            timeout: 0
        }
    });


    objOctokit.users.list().then(function (objResult) {
        debugger;
       alert(objResult);
    });
    chrome.runtime.onMessage.removeListener(getDataFromPopup);  //optional
}

I am giving the token from the developer settings and the url as https://api.github.com but the return is a list of 30 users which I dont even know.

Am in using Octokit correctly?

enter image description here

Expected : Only my User details.

Actual : List of 30 random users. As shown in image .

Nagendra Singh
  • 577
  • 1
  • 7
  • 24
  • What are you trying to do? What was the expected result? – Soviut Apr 27 '19 at 18:33
  • expected result would be to get the my username based on the token passed. for eg: when we hit rest api with token it should return me the result containing my username, but instead it return list of random users as shown above. – Nagendra Singh Apr 27 '19 at 18:34
  • Please update your question with those details, you'll get better responses to your questions if you do https://stackoverflow.com/help/how-to-ask – Soviut Apr 27 '19 at 19:15

1 Answers1

2

You're calling octokit.users.list() which lists all users.

Lists all users, in the order that they signed up on GitHub. This list includes personal user accounts and organization accounts.

To get the currently authenticated user

octokit.rest.users.getAuthenticated()

For more about the users routes, check out the documentation.

TheBotlyNoob
  • 369
  • 5
  • 16
Soviut
  • 88,194
  • 49
  • 192
  • 260