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

onLoginFailure being triggered every time #80

Open
tuladharjaa opened this issue Nov 2, 2020 · 49 comments
Open

onLoginFailure being triggered every time #80

tuladharjaa opened this issue Nov 2, 2020 · 49 comments

Comments

@tuladharjaa
Copy link

The login was working fine but after adding another Instagram tester user the "onLoginFailure" keeps triggering instead of "onLoginSuccess".

@Tymofiev
Copy link

Tymofiev commented Nov 2, 2020

I get this as well, it also gives a code in error response object, insead of token and HTML page is logged out into console.

@Dhanraj-bidchat
Copy link

i am also facing that issue.
Instagram Login was working yesterday also.
Now its throwing some 403 forbidden issue for android only

@rafalzawadzki
Copy link

Also facing the problem, Android only

@Nico-Guyon
Copy link

Nico-Guyon commented Nov 2, 2020

I have also the same problem, both on real android device and ios device.
Somehow the login is working correctly on ios simulator ...
Which is rather strange, the code executed being exactly the same.

The first code is correctly retrieved but it's the request to https://api.instagram.com/oauth/access_token which gets a 403 response (but not on ios simulator)

@Nico-Guyon
Copy link

Nico-Guyon commented Nov 2, 2020

Found the issue but this is rather unexplainable ...

Instagram changed the fields app_id and app_secret used with access_token to client_id and client_secret.
https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-access-token

So in the file instagram.js from your react-native-instagram-login replace the following code

form.append('app_id', appId);
form.append('app_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code);

with

form.append('client_id', appId);
form.append('client_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code)

And your login should work again.

Why the requests are working on the ios simulator and failing with a real device is totally beyond me though ...

@Rramandeep
Copy link

Rramandeep commented Nov 4, 2020

athorisation on instagram is returning code key instead of acess token key, as mentioned above you can make changes in libraray's main file accordingly.
here it is:
https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

@Dhanraj-bidchat
Copy link

Dhanraj-bidchat commented Nov 4, 2020

i forked and fixed the issue. Here is my package:
"react-native-instagram-login": "git+https://github.com/bidchatindia/react-native-instagram-login.git#v2"
You can use my package till they give update to this package.

@Rramandeep
Copy link

why not to copy lib code locally and change untill lib not updated.

@Dhanraj-bidchat
Copy link

@Rramandeep Our app is already live on store.
You will have to give new update to playstore for that anyways.
i made codepush to my users and done!

@Rramandeep
Copy link

@Dhanraj-bidchat no offence bro, but my app is under developement that's why.

@Dhanraj-bidchat
Copy link

@Rramandeep thats fine bro.
Nobody is forced to use my package.
Its for beginners who may find it difficult to do so.

@hungdev
Copy link
Owner

hungdev commented Nov 4, 2020

I updated the library, so you can remove the old version and install the new version. Feel free to comment here. Love guys.

@kiritm-nimblechapps
Copy link

Found the issue but this is rather unexplainable ...

Instagram changed the fields app_id and app_secret used with access_token to client_id and client_secret.
https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-access-token

So in the file instagram.js from your react-native-instagram-login replace the following code

form.append('app_id', appId);
form.append('app_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code);

with

form.append('client_id', appId);
form.append('client_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code)

And your login should work again.

Why the requests are working on the ios simulator and failing with a real device is totally beyond me though ...

You also change the appId to client_id

let ig_uri = `https://api.instagram.com/oauth/authorize/?client_id=${appId}&redirect_uri=${redirectUrl}&response_type=${responseType}&scope=${scopes.join(',')}`;

@hungdev
Copy link
Owner

hungdev commented Nov 5, 2020

@kiritm-nimblechapps I forgot it. Thank u. i updated.

@tuladharjaa
Copy link
Author

tuladharjaa commented Nov 10, 2020

Getting this on the "onLoginFailure"

Object { _: "" }

The latest package was working a while ago.

@hungdev
Copy link
Owner

hungdev commented Nov 10, 2020

@tuladharjaa can you give me steps to get onLoginFailure?
or send me a video about this

@tuladharjaa
Copy link
Author

The screen capture is on the following link:
https://drive.google.com/file/d/17zwnpqwRmwP11FqCm6DdBk9p-8sqA_5a/view?usp=sharing

The code I have used:
<Instagram
ref={instagram => {
this.instagramLogin = instagram;
}}
appId={config.igAppId}
appSecret={config.igAppSecret}
redirectUrl={config.igRedirectUrl}
scopes={['user_profile', 'user_media']}
onLoginSuccess={this.setIgToken}
onLoginFailure={(data) => console.warn("Failure", data)}
onClose={() => this.props.navigation.goBack(null)}
/>

@Nico-Guyon
Copy link

Tried to see if I had a login problem again on my app but it's working on iOS both device and simulator for me right now.

@tuladharjaa can you step into the library with the debugger and see what are the result of the instagram requests ?
Does anyone else also have a login problem again ?

@tuladharjaa
Copy link
Author

tuladharjaa commented Nov 10, 2020

The returned URL from WebView does not contain the codes. It just returns the redirectURL

I am getting this on an Android device.

@Dhanraj-bidchat
Copy link

@tuladharjaa you tried android login with same user that you loged in on iOS??
If your app is not live, always add new user as test user if not done

@tuladharjaa
Copy link
Author

@tuladharjaa you tried android login with same user that you loged in on iOS??
If your app is not live, always add new user as test user if not done

I have added the account as tester and was working previously on Android. I have not tried it on iOS.

@Dhanraj-bidchat
Copy link

@tuladharjaa can you try one common test account on both and let us know please?

@tuladharjaa
Copy link
Author

@tuladharjaa can you try one common test account on both and let us know please?

On iOS it is working fine.

@Nico-Guyon
Copy link

Just tried with an android emulator and it's working fine on my end.
I'll test later with a real android device and let you know if I can also reproduce the login pb.

@hungdev
Copy link
Owner

hungdev commented Nov 12, 2020

I just checked it again, it still works normally. I don't know the exact error.

@tuladharjaa
Copy link
Author

I installed the version 2.0.2 and then made changes on the Instagram.js file and it is working fine.

@denisprado
Copy link

Hey guys! Thanks for your efforts.. but, I'm receiving on onLoginFailure an object with the code. Anyone can help me?

@hungdev
Copy link
Owner

hungdev commented Nov 16, 2020

@denisprado show me your error, your code and your current version you are using

@denisprado
Copy link

@hungdev HI. My component is like that:

<InstagramLogin ref={ref => (instagramLogin = ref)} appId={igProd.appId} responseType="code" appSecret={igProd.appSecret} scopes={['user_profile', 'user_media']} redirectUrl={igProd.redirectUrl} onLoginSuccess={setIgToken} onLoginFailure={data =>console.log(data.code)} />

and I'm using the last version, 2.0.4. The error is the onLoginSuccess not receiving any data. I'm receiving a code onLoginFailure.

@hungdev
Copy link
Owner

hungdev commented Nov 16, 2020

@denisprado show me error from onLoginFailure func

@buraktt
Copy link

buraktt commented Oct 3, 2021

On v2.0.5 I'm having the same issue. It looks like a problem with the axios post call.
It's not adding the correct headers to the request, hence instagram is returning an exception.
(not sure why. never used axios before)

...
"data":{
"code":400,
"error_message":"Missing required field client_id",
"error_type":"OAuthException"
},
...

using fetch instead of axios fixed the issue for me:
https://github.com/hungdev/react-native-instagram-login/blob/master/Instagram.js#L71

let form = new FormData();
form.append('client_id', appId);
form.append('client_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code);
let res = await fetch('https://api.instagram.com/oauth/access_token', {
  body: form,
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
})
if (res.status === 200) {
  const responseJson = await res.json()
  this.props.onLoginSuccess(responseJson, results);
} else {
  this.props.onLoginFailure(results);
}

@tienle46
Copy link

tienle46 commented Dec 16, 2021

I'm also having this issue on 2.0.5. Calling 'https://api.instagram.com/oauth/access_token' returning Forbidden 403 on Android, even it was working fine yesterday. Anyone got solution for this ?

@Tymofiev
Copy link

I'm also having this issue on 2.0.5. Calling 'https://api.instagram.com/oauth/access_token' returning Forbidden 403 on Android, even it was working fine yesterday. Anyone got solution for this ?

The issue returned as unexpected as gone for me. I've been trying for an hour to figure out what the problem is and for now I see the possible issue with setting the cookies along with returning the response, seems like axios needs to be configured correctly for this.

@cisplRejjak
Copy link

@Tymofiev did you find any solution for this?

@Dlas1212
Copy link
Contributor

+1

1 similar comment
@unixkapl
Copy link

+1

@tienle46
Copy link

I'm also having this issue on 2.0.5. Calling 'https://api.instagram.com/oauth/access_token' returning Forbidden 403 on Android, even it was working fine yesterday. Anyone got solution for this ?

The issue returned as unexpected as gone for me. I've been trying for an hour to figure out what the problem is and for now I see the possible issue with setting the cookies along with returning the response, seems like axios needs to be configured correctly for this.

I have tried using Fetch as @buraktt suggested but it still returned Network Error which I guess is the same with axios error. Still looking for any solution.

@Tymofiev
Copy link

@Tymofiev did you find any solution for this?

Looks like issues appears because of spaming with /oauth/access_token, tried on another account and it worked. Found some descriptions on 403 errors in here https://developers.facebook.com/docs/instagram-basic-display-api/reference/error-codes/ It says that error could be thrown when Rate limit exceeded.

@hungdev
Copy link
Owner

hungdev commented Dec 20, 2021

@Tymofiev did you find any solution for this?

Looks like issues appears because of spaming with /oauth/access_token, tried on another account and it worked. Found some descriptions on 403 errors in here https://developers.facebook.com/docs/instagram-basic-display-api/reference/error-codes/ It says that error could be thrown when Rate limit exceeded.

But i tried with postman with the same account, and it still works. I don't know exactly where the problem is coming from.

@hungdev
Copy link
Owner

hungdev commented Dec 20, 2021

And we should only discuss in 1 thread. Please don't discuss the error: returned 403 here to avoid distractions
Everything related to returned 403 should discuss in
#102

@Tymofiev
Copy link

@Tymofiev did you find any solution for this?

Looks like issues appears because of spaming with /oauth/access_token, tried on another account and it worked. Found some descriptions on 403 errors in here https://developers.facebook.com/docs/instagram-basic-display-api/reference/error-codes/ It says that error could be thrown when Rate limit exceeded.

But i tried with postman with the same account, and it still works. I don't know exactly where the problem is coming from.

Hmm, one more thing that I noticed that it didn't work when I didn't receive notification on IG app about new login from some browser. Have no idea how it can be connected though

@Dlas1212
Copy link
Contributor

I solved the issue and still not sure why it doesn't work.

/authorize works and returns you the code. You may use PostMan on /access_token and it works. Although using /access_token within the package throws a 403. Switching axios -> fetch, still throws the same error ONLY on /access_token.
This has nothing to do with rate limits since you can literally get the values from another spot.

What I ended up doing is making an API call to my main application (PHP app) which I pass the CODE from /authorize. Then doing the EXACT same call to /access_token and returning the token.

Not sure why this method works since it's exactly the same, but doing the call within the app is getting blocked.

@alyn3d
Copy link

alyn3d commented Dec 20, 2021

@Dlas1212 You're talking about making the call within redirectUrl on backend, right?
Then how do you capture the access_token on the frontend side, cause react-native-instagram-login is looking for the code in querystring.

@Dlas1212
Copy link
Contributor

InstagramLogin - leave the app secret key empty, which will return you the authorize code in loginSuccess(). Then make your api call - pass the code - do the /access_token there and return access_token to your app.

@alyn3d
Copy link

alyn3d commented Dec 20, 2021

Oh, now it makes sense to me. Thank you :)

@sujay-bidchat
Copy link

#102 (comment)

@bleszerd
Copy link

Found the issue but this is rather unexplainable ...

Instagram changed the fields app_id and app_secret used with access_token to client_id and client_secret. https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-access-token

So in the file instagram.js from your react-native-instagram-login replace the following code

form.append('app_id', appId);
form.append('app_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code);

with

form.append('client_id', appId);
form.append('client_secret', appSecret);
form.append('grant_type', 'authorization_code');
form.append('redirect_uri', redirectUrl);
form.append('code', code)

And your login should work again.

Why the requests are working on the ios simulator and failing with a real device is totally beyond me though ...

I wanted to highlight this answer, it's simple, but it solved my problem

@Dlas1212
Copy link
Contributor

Found the issue but this is rather unexplainable ...

Instagram changed the fields app_id and app_secret used with access_token to client_id and client_secret. https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-access-token

So in the file instagram.js from your react-native-instagram-login replace the following code

form.append('app_id', appId);

form.append('app_secret', appSecret);

form.append('grant_type', 'authorization_code');

form.append('redirect_uri', redirectUrl);

form.append('code', code);

with

form.append('client_id', appId);

form.append('client_secret', appSecret);

form.append('grant_type', 'authorization_code');

form.append('redirect_uri', redirectUrl);

form.append('code', code)

And your login should work again.

Why the requests are working on the ios simulator and failing with a real device is totally beyond me though ...

I wanted to highlight this answer, it's simple, but it solved my problem

It's already using client_id and client_secret

@duongquang1611
Copy link

does anyone have a solution? i used fetch still get 403 error

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

No branches or pull requests