Swift 2 OAuth2 LinkedIn connection - ios

I'm gonna make an native iOS app with Swift 2 and Xcode 7. The users should login using LinkedIn and OAuth 2 but I'm wondering how I should begin to set this up. I don't have many experience with OAuth 2.
Is there a good tutorial or a sample app? I saw the Ray Wenderlich post but that comes with an existing project. I want to build an app with LinkedIn login from scratch.
EDIT
I want to use the LinkedIn login to get the user's connections and send them notifications. I was researching this and I found some pages that said that connections can't be retrieved from the new LinkedIn API, is this true? It is not possible to get someone's connections from LinkedIn in a native iOS applications?

You should start with LinkedIn guide for LinkedIn and OAuth 2 .
But still if you need a sample for Authentication with OAuth 2 here it is .
For your second question related to the connection yes Linked have made changes but the API is still available but for the partners .
If you are an existing LinkedIn partner, these changes will not impact your existing partnership or the associated APIs that your partnership allows you to access.
If you are experiencing issues as a result of the May 12th changes, please reach out to your LinkedIn Business Development representative immediately.
For further details you can see Developer Program Transition Guide.

Check out this repo, I did this swift pre-2.0 but it shows you the basic algorithm. You can do it the with your secret hard coded or fetch it from the server. The key is getting the oath header just right which is a huge pain
https://github.com/GregPrice24/SwiftStream

Check this out: https://github.com/jeyben/IOSLinkedInAPI
I used this repo and successfully implement LinkedIn integration in my App. It is in Objective-C but you can use Cocoapods and import them as Frameworks and use in swift2 with no trouble.
Note: As of the 12´ May 2015 LinkedIn applied restrictions to API usage for all non partners: See: https://developer.linkedin.com/blog/posts/2015/developer-program-changes
So you can only get the basicprofile at the beginning, but you can apply for the partner program to get those extra information such as connections here: https://developer.linkedin.com/partner-programs

Related

How to authenticate using the installed Twitter app

If the user is logged-in with the native Twitter app installed, I want my app to open the Twitter app to request authorization.
I already implemented the flow to get the oauth_token in order to start the login process through Twitter's api. Only, the current API Documentation do not mention anything about how to use the native iOS app in the process. It only sends back a url for the user to log in.
let url = URL(string: "https://api.twitter.com/oauth/authorize?oauth_token=\(result.oauthToken)")!
DispatchQueue.main.async {
UIApplication.shared.open(url)
}
On getting the requested oauth_token, I get this link. Opening the link will display a Webview to login. Not the native Twitter iOS app.
I tried to use a deeplink to manually launch the Twitter app, but I couldn't found any resources on how to setup the link properly.
So far I have tried things like:
twitterauth://authorize?consumer_key=[KEY]&consumer_secret=[SECRET]&oauth_callback=swifter-[KEY]
or
twitterauth://authorize?oauth_token=\(result.oauthToken)
without any success...
As mentioned in another post, Clubhouse has implemented exactly this flow. So it is possible. The question is how ? 😅
This flow seems to have not been officially supported since the retirement of TwitterKit on May 1, 2018. Any applications that still offer this functionality to their end users likely have some sort of partnership with Twitter to allow for this which is otherwise undocumented publicly.
The reasoning for this was detailed sparsely in a related Twitter Developer Forums thread:
Unfortunately at this time we have had to make some incremental adjustments that are not so smooth for everyone; especially as you’ve found, for mobile app developers. We’re in the middle of a transition to a new API platform (via Twitter Developer Labs) and there will be some changes as we go along - we are asking for your feedback to help us, and if you check the ideas, authentication and authorization is something we’ve heard a lot about.
I cannot tell you today exactly when we’ll get to an enhanced solution, but this is something we are actively working on.
Direct link
The official guidance is to use the traditional WebView method until Twitter officially re-releases this capability:
I don’t believe that this is possible any longer, so I would encourage you to use the full OAuth flow. I apologise that this may not be what your users prefer, but this is the documented way to gain authorisation (we do not document or support URL schemes for the native iOS app).
Direct link
We do not support or document any means of users signing in to Twitter outside of the OAuth flow; any use of undocumented features is subject to change without notice.
Direct link
As linked above Twitter appears to be soliciting feedback on this via their UserVoice page, should you feel so inclined to suggest the re-implementation of such a feature.

Using LinkedIn's iOS 9 SDK for authentication with a webview instead of LinkedIn's mobile app

My iOS app currently offers users the option to log in and sign up with their LinkedIn accounts. I am using this project for the LinkedIn log and OAuth: LinkedInOAuth
With the update to iOS 9, my app now occasionally crashes, when a user attempts to log in through LinkedIn using that project, with a runtime exception of WebThread(18): EXC_BAD_ACCESS(code=1, address=0x8)
To resolve this occasional crash, I turned to an updated version of the project I was using that conforms to ios 9 and linkedin's ios 9 SDK.
The issue is that while this new project has solved the WebThread crashing, it now requires users to download LinkedIn's app (if they don't have it) in order to log in to my app with LinkedIn.
The previous project never had such requirements and would present a webview that allowed anyone with a linkedin account to log in.
My question is am I wondering if it is possible to authenticate with LinkedIn in ios 9 without requiring the user to download the mobile app? My hopes are that it is possible to update the old project to conform to ios 9 while simply presenting a webvew. Thank you!
We only discussed this last week (at the time your question didn't have an answer, but happy to update you now—that is, if you haven't solved this in the meantime).
After scouring several sources I came across this:
Mobile vs server-side access tokens
Presently, there is no mechanism available to exchange them. If you
require tokens that can be used in both the mobile and server-side
environment, you will need to implement a traditional OAuth 2.0
solution within your iOS environment to acquire tokens that can be
leveraged in both situations.
from: https://developer.linkedin.com/docs/ios-sdk-auth
The premise being that via mobile solutions, they offer single sign-on thru their app. This works, but requires their app. Apple's approval process has swung both ways on this, and it appears that it is a flip of the coin as to whether they will allow this or not (the requirement of a third party app). #AroundThen didn't have any luck and his app was rejected due to the requirement, however, other users* have indicated Apple weren't adverse to it in their application processes.
Alternatively, their is the web logon process using OAuth2. This is pretty stock for their non-mobile solutions. Currently sharing the tokens between mobile and web solutions is not a default and if you want to share the same token their solution is that that is listed above.
In essence (and copied from my other answer here):
You can test for the presence of the linked-in app:
if it is not there: implement OAuth2 directly through your app
if it is there: use it or your OAuth2 implementation (which you'd probably err on the side of using their app for the link-ability between any features of the app you may need in yours).
Thereby avoiding the REQUIREMENT to have the app installed, but utilising it if it is.
This suggests that authentication away from the app is supported.
Reportedly, #AroundThen has had success with this process.
Good luck!
*1 I'm currently having trouble finding his post, but basically he provided login credentials that Apple attempted to use, but had locality issues and hence couldn't get in, but it was inferred they may have approved it if they had of.

Swift iOS Twitter API Fails

I am trying to load some twitter feeds of a user on Swift iOS App. On twitter Documentation, I found the API is:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
which returns:
{"errors":[{"message":"Bad Authentication data","code":215}]}
Older Rest API did not require. Newer API requires authentication.
Requires authentication? Yes
How do I get that working? Any tutorials would be even sweeter!
Before marking this question duplicate please bear in mind that I have done a good search and none of the answers answered my questions because a lot them point to older Rest APIs.
Take a look at Twitter Fabric http://dev.twitter.com/fabric which is a free SDK (compatible with Swift) that provides easy authentication via either guest or user login. Sample app written in Swift at https://github.com/twitterdev/cannonball-ios
If you would prefer to use raw REST calls against the API, follow the OAuth details in our dev documentation https://dev.twitter.com/oauth
In settings of your simulator go to accounts -> Twitter, and login there in actual twitter account. As you try to login, it doesn't know what user to use, so you need to specify it.

Update your app to support OAuth 2.0 before 12/13/1

I am using the following java script api for facebook connect http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php
Then i received this email from fb
Dear Developer,
As part of our continued efforts to migrate all apps to OAuth 2.0, we opted in all apps using the new JavaScript SDK to OAuth 2.0 this afternoon at 11am PT and reverted at 1:30pm because we noticed that your app has not migrated. Please ensure that you have set the oauth param in FB.init to true and that you are using FB.getAuthResponse to obtain the access token.
Read more in the OAuth2 migration announcement, updates to the new JS SDK blog post, or our JS SDK docs.
But i did't updated my fb connect implementation and it is still working fine. I am not sure will this effect my fb connect in future? and secondly why my implementation is still working fine? Any help will be really appreciated.
You should use the new version as soon as possible. I've been dealing with Facebook and their various APIs for four years now. This is the most warning they've ever given for deprecating anything, so this is big for them. Upgrade your websites ASAP. :)

Posting twitter updates using basic authentication not working

I've tried a couple of ways (http://emmense.com/php-twitter/ and http://www.webmaster-source.com/2009/04/05/post-to-twitter-from-a-php-script/) to post updates to my twitter account but I am getting the response:
Basic authentication is not supported
I had a look at the twitter website and they said something about the new OAuth for authentication. Is this why my code isn't working?
Does anyone know of some PHP code that works?
This is correct. They recently adopted OAuth as their sole login platform for 3rd party apps as a security precaution.
Check out their developer area for examples:
http://apiwiki.twitter.com/w/page/22554657/OAuth-Examples
Basic auth is deprecated now. Check out this library https://github.com/abraham/twitteroauth for using OAuth in your application
It took me several hours to create this PHP script but it is working. Just make sure that your hosting company supports cURL. If you don't need the geo features you can cut them out.

Resources