Currently I am working MVC4.5 with razor,
I have try to integrate Twitter API in My Application but no luck. Could you please help me how to integrate Twitter API in my Application. I have create twitter API which details following
OAuth settings
Access level Read-only About the application permission model
Consumer key - [ConsumerKey]
Consumer secret - [ConsumerSecret]
Request token
URL https://api.twitter.com/oauth/request_token Authorize
URL https://api.twitter.com/oauth/authorize Access token
URL https://api.twitter.com/oauth/access_token Callback
URL http://www.opalevents.org/
Okay, this isn't short and I can't tell you the whole process just with a few lines or even showing some code, but I'll try to give you the directions.
1. Authentication
First of all , most of Twitter API calls need to authentication (using your consumer keys). To authenticate you have to request twitter oAuth TOKENs (that's why request and authorize URL). Without these tokens, you aren't able to make requests for API calls that require authorization.
Authentication is made via oAuth (a lot of plataforms uses oAuth to authenticate, so familiarize with that):
https://dev.twitter.com/docs/auth/using-oauth
You have not specified what you need to integrate, but here explain how you need to authenticate by what you need to integrate:
https://dev.twitter.com/docs/auth/obtaining-access-tokens
if you want to work with user data, you need this authentication: https://dev.twitter.com/docs/auth/implementing-sign-twitter
The basic flow is:
With your consumer keys you request a token to twitter
You'll redirect your application to twitter, to user sign in via twitter
Twitter will throw back to your CALLBACK URL the secret token to make API calls
again, this is a brief, that's all detailed at mentioned docs above
2. Making API calls
Twitter provide a lot of services through their REST API, the documentation is great, and you can find what you need to use easily:
https://dev.twitter.com/docs/api/1.1
Basically each service method have its own url and required parameters for making a call. And when you provide it, you'll receive a (JSON) response.
To help debug, they provide an amazing API explorer, that helps A LOT:
https://dev.twitter.com/console
3. Twitter Libraries
Finally we have some library for twitter written for .NET:
https://dev.twitter.com/docs/twitter-libraries
https://github.com/danielcrenna/tweetsharp
http://linqtotwitter.codeplex.com/
Twitterizer was an amazing library, but seems they have stopped support:
https://github.com/Twitterizer/Twitterizer
some Twitterizer example at Twitter:
https://dev.twitter.com/docs/auth/oauth/single-user-with-examples#csharp
if someone know good ones, please edit this post.
4. Most important
And if you have some question, don't be afraid to research, read , read and read here: https://dev.twitter.com/docs
Related
In my application, I want to fetch data from Zoho Subscription Api which implement OAuth 2.0 documentation mechanism. As per the documentation first I need to generate a grant token using which I need to generate the original access token. For this, I have to hit the URL which will open the Zoho Authorization window in the browser and after I allow the authorization it will provide me the code which I can use for the next step.I want to get that code without opening the browser window as Postman does. How to do that in .net and with Restsharp.
Sample URL is
https://accounts.zoho.com/oauth/v2/auth?
scope=ZohoSubscriptions.invoices.CREATE,ZohoSubscriptions.invoices.READ,ZohoSubscriptions.invoices.UPDATE,ZohoSubscriptions.invoices.DELETE&
client_id=1000.0SRSZSY37WMZ69405H3TMYI2239V&
state=testing&
response_type=code&
redirect_uri=http://www.zoho.com/subscriptions&
access_type=offline
Zoho API link - https://www.zoho.com/subscriptions/api/v1/oauth/#overview
Thanks
Utpal Maity
I am new to .NET core and while I have .NET experience, I have never built authentication, in the past I've always worked on project not started by me. I am just trying to learn and find good resources and I would greatly appreciate if anyone knows tutorial or if it can explain how to solve this.
When using external logins, I followed those instructions here. This all works well if I create simple web api project and run, I get a web page where I can login, authenticate, works perfect. But this is not my end goal, I am building Web APIs not a Web Application. In my case let's say I have iOS and Android apps and my external login is done on the app itself, how would I pass token to Web APIs? I want to use [Authorize] method in Web APIs to make sure that no un-authorized access is made agains APIs and in addition to that I would like to use roles.
I am assuming token information is passed in header. But what is the header name for token? Can external authentication be used with roles or that is only possible if I store username/password? Can you point me to some good tutorial or anywhere I can learn more because all google search returns back to same like I have mentioned above and it is not very descriptive.
In general , your web api will work like a identity provider , it will issue and validate the JWT tokens :
http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/
You can also implement authorization with the help of your external login provider .If you have SDK or own code in your client app to help do authentication , for authorization part , you can also register your web api in the same identity provider . For example , you are using the google authentication external login in your client app , you will should register your client app and web api on google's application registration page , then you could use OpenID Connect hybrid Flow to authentication user and get access token for accessing web api . Each identity provider provides how to implement authentication/authorization with lots of documents.
You can have an endpoint that allows anonymous access and takes the token and verifies it. Then it can send back a JWT that contains claims/roles that you want to enforce on the specific user. Every time the client accesses a secure endpoint, it can send your JWT in the header which gets verified before the specific method in your API controller is called. You can look into OAuth flows if you want to integrate social logins.
For example, Google has this documentation for OAuth-
https://developers.google.com/identity/sign-in/web/backend-auth
The documentation claims:
"The Firebase JavaScript, Java, and Objective-C libraries provide built-in functionality for many login providers, but the REST API works a little differently. ... generate user login tokens with your own server side code."
There appears to be no library for .NET/Xamarin, so I need to use the REST API. But there is no "own server side code" on Firebase.
I'm interpreting this to mean I need a separate service (not Firebase) to host software to provide the registration and authentication endpoints. Do I have that right?
Yes it can! (answering the question in title title)
I just fiddlered (is that a word?) how the javascript SDK talks to firebase servers and it turns out it is quite straightforward.
At the beginning you let your user authenticate with your provider of choice (e.g. facebook). You grab the oauth access token and you POST that (don't forget the "application/json" header) to the following location:
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=<YOUR API KEY>
The post data would like like this:
{
"postBody":"access_token=<OAUTH ACCESS TOKEN>&providerId=<PROVIDER ID>",
"requestUri":"http://localhost",
"returnSecureToken":true
}
The <PROVIDER ID> can be one of the following
facebook.com
google.com
twitter.com
github.com
In return you get a nice json which contains a lot of information, one of which is the "idToken" which acts as the authentication token for making REST requests to firebase. You can set it as the "auth" URL parameter of your request.
I wrote a library to handle this (along with email+password & anonymous logins):
https://github.com/step-up-labs/firebase-authentication-dotnet
And I wrote a blog post about it:
http://blog.bezysoftware.net/firebase-authentication-csharp-library/
Yes and No.
You could create binding projects and use the existing FirebaseUI iOS and Android libraries
Xamarin Binding walk-throughs:
https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/
https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/
Firebase mobile libraries:
https://www.firebase.com/docs/android/
https://www.firebase.com/docs/ios/
Otherwise, yes, you are correct, you would need to provide your own server side authorization system.
The need for a server when using REST is not for the actual authentication (Although you will have to solve this issue too somehow), but for generating the tokens that can be used for the client to authenticate against the Firebase REST API.
From the documentation
To authenticate a user with Custom Login, we must provide each client with a secure JWT that has been generated on a server. There are several helper libraries for generating JWTs given a Firebase app's secret. Our secret can be found under the Secrets tab in our Firebase app's dashboard.
Then you could attache this token to REST requests to be authenticated:
'https://docs-examples.firebaseio.com/rest/saving-data/auth-example.json?auth=SERVER_GENERATED_TOKEN'
My app used to be able to log into Tumblr, but late last year they changed their api to use OAuth. I am having a hell of a time trying to log in to Tumblr programmatically from a client-side app. I am using this app as a guide. Everything seems all right, but I keep getting Missing or invalid request token from Tumblr.
My question is this: is there an actual working example of logging in to Tumblr via OAuth in C#?
Temboo simplifies the OAuth process for Tumblr by breaking it down into two calls:
InitializeOAuth - returns a Tumblr authorization URL that you can show to your users and have them grant your application access to their Tumblr account.
FinalizeOAuth - returns the access tokens your app needs for authenticated access to Tumblr accounts.
You can experiment with Temboo's Tumblr OAuth support in your browser from the link below, and then generate the source code you need to use this behavior in your app with the Temboo SDK. If your language isn't supported (Temboo does not currently have a C# SDK), you can generate REST API cURL commands.
https://www.temboo.com/library/Library/Tumblr/OAuth/
(Full disclosure: I work at Temboo, so let me know if you have any questions!)
I need to access the Twitter API user timeline service using the following REST request so I can pull some tweets from a feed to display on a site:
"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=frosario"
It works mostly, but I'm getting sporadic 401 and 500 errors when performing this request; which seem to be because I'm hitting the rate limit for unauthenticated API calls.
I'd like to authenticate with my client Id and secret so I can take advantage of the increased rate limit. I'd like to do this with a server side OAuth flow just using my client id and secret; but could also provide user credentials if needed. However, this needs to be all server side; I can't go through the OAuth redirect flow to authenticate with Twitter's API everytime we load up the site; just to download these tweets. What are my options? I looked over Twitter's OAuth documentation and didn't see anything that would seem to work for my situation; but perhaps I missed something.
Any constructive input is greatly appreciated.
When using oAuth you're using it to authenticate the current user so that you can access their specific tweets and such, which isn't what you're looking to do. You're just looking for a way to download certain tweets right?
You can create a console app or process to download the tweets for you, store them in a database, then read from your database.
If there is a lot of tweets, I'd recommend using the Twitter Stream API.
You just need to authorize your application once.
Check out the MVC quickstart in the Spring Social Twitter extension:
http://www.springframework.net/social-twitter/