jodybrewster / react-native-linkedin-login

React Native Linkedin login
71 stars 42 forks source link

Cannot setup the linkedin login #25

Closed aleproust closed 7 years ago

aleproust commented 7 years ago

Hi, I'm trying to use your project on a new project I started. Because I'm pretty new with react-native, I followed your readme and tried to create my first login page with linkedin based on your example.js file. But without success... The problem I got when I click on Sign in with Linkedin is generic...

SyntaxError: Unexpected token u in JSON at position 0

Should be great to juste have quick example in the readme.

sarahcassady commented 7 years ago

If JSON.parse is given something other than a string it will complain with this error. u is what gets left over from the undefined literal when attempted to be parsed as a string. The code in example.js is catching an error in login() and indeed trying to parse it, so you can dump the error object into the log to see what was actually returned, such as:

login() {
  (...)
    }).catch((e) => {
      console.log(e);
      // var err = JSON.parse(e.description);
      // alert("ERROR: " + err.errorMessage);
      // console.log('Error', e);
    });
  (...)
}

This might be a legitimate bug since getUserProfile() and getUserProfileImage() don't try to parse the caught error, so I'm not sure why login() is different in the example.

Anyway, if you haven't set up your LinkedIn app completely (such as forgetting to add your iOS Bundle Identifiers), a sign-in attempt would throw an error like this:

Object {error: "Error Domain=LISDKAuthError Code=5 "(null)" UserIn…ISDKServerError, errorInfo=invalid_os_identifier}"}error: "Error Domain=LISDKAuthError Code=5 "(null)" UserInfo={errorDescription=either bundle id or package name / hash are invalid, unknown, malformed, originalDomain=LISDKServerError, errorInfo=invalid_os_identifier}"__proto__: Object
jodybrewster commented 7 years ago

@aleproust Sorry I've been meaning to work on the readme a bit more. Were you on iOS? I'll fix here soon.

alexandrzavalii commented 7 years ago

I have the same error, is something missing in the setup ?

alexandrzavalii commented 7 years ago
LinkedinLogin.login().then((user) => {});

Shouldn't we pass credentials to the login ?

jodybrewster commented 7 years ago

Under iOS make sure you follow the "Configure your Bundle ID" section in the linkedin docs ... https://developer.linkedin.com/docs/ios-sdk. Your appid also needs to be added to your info.plist in ios like in the below code see li4443524. Add li and whatever your app id is. My app id is 44443524. Also add to LIAppId field. Not sure if that fixes both of your problems, hopefully this helps.

Also remember to add the objc code to your app delegate or you won't get a response from linkedin.

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>linkedin.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>li4443524</string>
            </array>
        </dict>
    </array>
    <key>LIAppId</key>
    <string>4443524</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>linkedin</string>
        <string>linkedin-sdk2</string>
        <string>linkedin-sdk</string>
    </array>
alexandrzavalii commented 7 years ago

@jodybrewster I did it, thats not the issue.

Will the login work in the emulator? App id is client id ?

jodybrewster commented 7 years ago

@alexandrzavalii No ios specifically won't run in the emulator since it relies on the linkedin app to be installed. Android yes, you can install the linkedin apk or download from google play in emulator. I believe app id and client id are different.

There actually should be a pop up stating you need to install the linkedin app. If its not saying that then that's a bug I need to fix

alexandrzavalii commented 7 years ago

@jodybrewster Oh okay, so this was the problem. The app has to be installed. I didnt't see the popup.But after I built it on the device it worked.

I guess I have to use oauth instead, because I dont like this flow. Thanks!

jodybrewster commented 7 years ago

Just curious as to why you don't like this flow? Can you expand on that, is there something that I could change to help you more? Any feedback is much appreciated. I'm going to close this issue, glad I could help you both!

alexandrzavalii commented 7 years ago

@jodybrewster its just not a very good user experience. What if you don't want to install the linkedin app, you just want to log in with your linkedin profile. Hey but plugin is great, good job!

I think oauth will open a browser inside my app with linkedin login form straight away.

jodybrewster commented 7 years ago

@alexandrzavalii If you can get that running I'll add it in as a backup.

bisht2ankit commented 6 years ago

@jodybrewster I am not getting any response back after login with linkedin?