Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect access token should not be allowed #64

Open
AvaniVerma opened this issue Aug 14, 2017 · 9 comments
Open

Incorrect access token should not be allowed #64

AvaniVerma opened this issue Aug 14, 2017 · 9 comments

Comments

@AvaniVerma
Copy link
Contributor

AvaniVerma commented Aug 14, 2017

Steps to reproduce

  1. Add anything random as access token

Result : We get a screen saying fetching results. However, all that happens is failed requests.

In ideal conditions, we should see an error and ask the user to re-enter the access token.

@AvaniVerma AvaniVerma reopened this Aug 14, 2017
@AvaniVerma AvaniVerma changed the title hould Incorrect access should be handled Aug 14, 2017
@AvaniVerma AvaniVerma changed the title Incorrect access should be handled Incorrect access token should not be allowed Aug 14, 2017
@mayakarabula
Copy link
Contributor

Hello @AvaniVerma

I looked into this issue but I saw that you put v2 tag on it. In v2 you are using passport js and call /user address to get user information and token for github. To some extent it ensures that the token is correct otherwise you won't login.
Nonetheless you can put extra check by calling general github API url https://api.github.com/?access_token=${accessToken} when token is incorrect it returns 401 error, otherwise 200. So you can put Error: token is invalid instead of sending many requests.

However I assume you meant that this bug occurs in v1, which is true and can be fixed with a call to general github API url like before. Here is an example code:

https://github.com/curiositylab/curiosity/blob/master/js/main.js#L93

const url = `https://api.github.com/?access_token=${token}`;
axios({
    url,
    method: 'get',
    responseType: 'json',
}).then(() => {
    localStorage.setItem('accessToken', token);
    resolve();
}).catch(() => reject('Error: invalid token'));

I also found a bug in v1 that when you write the token for the first time you don't save USERNAMES in localstorage, this should be done before getData

Would you like me to create a PR to fix it in v1 or v2 or maybe both?

@mubaris
Copy link
Owner

mubaris commented Sep 10, 2017

Doing a single PR for both will be better

@mayakarabula
Copy link
Contributor

Hi @mubaris I don't really understand what you mean here by a single PR for both, the code for v1 and v2 is different now so it have to be separate commits (not cherrypicked)

@kriswep
Copy link

kriswep commented Oct 5, 2017

wouldn't it be nicer if an OAuth app would be set up?
Then users wouldn't have to generate acces tokens and wonder over necessary scope settings at all.

@simeg
Copy link

simeg commented Jan 26, 2018

It should say in the README what scopes is required for the token. I can't find this information anywhere and it's very important. If a user doesn't know what scopes to give he/she might give all scopes which gives this application unnecessary power.

@adwsingh
Copy link

Is this still open?

@mubaris
Copy link
Owner

mubaris commented Mar 19, 2018

@MehWhatever Yes

@mubaris
Copy link
Owner

mubaris commented Mar 19, 2018

@simeg You can create a token without any scopes

@technolaaji
Copy link

technolaaji commented Oct 1, 2019

const getData = function getData() {
    document.getElementById('searching').innerHTML = '<br/>Fetching projects...';
    usersCurrentCall = 0;
    callInProgress = true;
    reqNo += 1;
    USERNAMES.forEach((username) => {
        const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`;
        axios({
            url,
            method: 'get',
            responseType: 'json',
        }).then((response) => {
            dataCollector(response, username);
        }).catch((err) => {
            console.error(err);
        });
    });
};

so this is the function that calls for the projects for a specific user right? but the issue is that you are always getting fetching projects if a user provided an incorrect access token

keep in mind that if you provided a incorrect access token then it should be appeared in the console.error that is inside of the axios catch

first you should clear the child inside of the element searching so that the 'fetching products' text goes away https://www.w3schools.com/jsref/met_node_removechild.asp

then you should insert in the inner html of searching 'incorrect access token' or 'something went wrong please try again!'

so it should be something like this:

const getData = function getData() {
    document.getElementById('searching').innerHTML = '<br/>Fetching projects...';
    usersCurrentCall = 0;
    callInProgress = true;
    reqNo += 1;
    USERNAMES.forEach((username) => {
        const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`;
        axios({
            url,
            method: 'get',
            responseType: 'json',
        }).then((response) => {
            dataCollector(response, username);
        }).catch((err) => {
            let searching = document.getElementById('searching');
            searching.removeChild(searching.childNodes[0]); // assuming it is the first element so it removes the 'fetching projects' text
            searching.innerHTML = '<br /> Something went wrong! please try again later'
            console.error(err);
        });
    });
};

this is a basic example but if you want to be specific, you can either innerHTML the error being catched by axios or you can receive the error and do some validation

hope my answer helped a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants