I am attempting to connect to Yammer using their .NET SDK but I am having a hell of a time managing this... The point of this exercise is to create an application in Azure which periodically - and AUTONOMOUSLY - contacts Yammer and fetches the latest messages from a specific Yammer group.
Does anyone know of the correct way to use the Yammer .NET SDK from, let's say, a console application, which does not rely on a browser (a.k.a. direct user interaction) to successfully connect via OAuth authentication?
What I have tried:
Trying to suss out what to do from the example given on .NET SDK page on developer.yammer.com, you can see under "Standard Process" an example which shows the LaunchSignIn() function with an incorrect signature! The example shows the usage as:
var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled);
whereas the actually signature I get from the dll is:
void OAuthUtils.LaunchSignIn(string clientId, string RedirectUri)
I'll forgive the missing ssoEnabled parameter... but the example claims the function receives a response, from which a Code is then extracted. This is, of course, the piece missing from my attempt to call:
(awaitable) Task<AuthEnvelope> AuthClient.AuthenticateAppAsync(string code)
I have scoured Google for information on the use of the Yammer .NET SDK but have come up empty handed. All manner of examples of connecting to Yammer but none are in any way relevant to the .NET API. The only thing in any way relevant that I have seen is the Yammer .NET API example uploaded, apparently, by the person who developed it, who posted the code on GitHub. I have checked this example but the two parts in it - one for Windows Phone and one for Windows "Modern App" - both rely on a Browser object being available, or something to that effect anyway. There are redirects, I'm supposed to have a RedirectUri for Yammer to direct me... So does this other example - which was the ONLY other example of using the .NET SDK that I could find.
I imagine that the reason the signature is different is because this isn't actually the same function at all. The one I am trying to use is in Yammer.Oss.Api.Utils whereas the example application doesn't even have the letters Utils together other than in the name of the class OAuthUtils... which leads me to believe that it is possibly under Yammer.Oss.Core.WinRT which, as luck would have it, I cannot reference at all... Yammer.Oss.Core only contains Collections, Constants, Extensions and Serialization.
By the way, in the announcement of the .NET SDK (see first link above), the link to documentation for the SDK leads to the Yammer Support page.
Skip the .NET SDK and just do the authorization yourself using the server-side flow. Then make the requests with HttpClient and add the Authorization header. The SDK might be helpful with some Modern Apps but it's overkill for most people. When working with the API manually the worst thing you'll have to deal with is deserializing the JSON responses with JSON.NET, or other JSON library.
You don't say what you are trying to build, but AFAIK WebJobs don't have a UI so you'll need to do the authorization from a console app or website. Then store the resulting OAuth token somewhere that the WebJob can access it. If you have need an OAuth token per user you'll need to store those in a database, but make efforts to protect them because each OAuth token provides access to their Yammer account.
Related
I have a mobile App in Android that successfully authenticated with Google api returning id-token and also profile information. Now I need to integrate it with my login and registration which I use .net web api as backend. I found google explaind article but not with c# and nuget library and microsoft docs is little difficult to follow. It will be better if i can integrate it with Identity that visual studio provides when creating new project with user authentication generated.
thanks in advance
I resolved my confusion next day after little digging and trying>
Ok first there are two ways of authenticating with third party which i was mixing them and I got confused.
First one in which your application is web or mobile but with web view.
Second way (that I'am using) in which native android activity handle going to google api, so the resulted id-token I manually send it to my api and use this code in c# to verify, requires Google.Apis.Auth library from nuget
var Payload = await GoogleJsonWebSignature.ValidateAsync(idtoken);
See image of steps need to follow in the second way
For more info:
https://youtu.be/zZt8SFivjps
https://developers.google.com/identity/sign-in/android/start-integrating
https://developers.google.com/identity/sign-in/web/backend-auth
I am coding against the OneDrive C# SDKand I have a few questions.
Question 1.
Does the OneDrive C# SDK use the Microsoft Graph API under the hood?
... If so, how can I use the SDK to pass in my client_Id and client_secret and authenticate as a service or daemon app instead of a traditional OAuth for a user?
I have proofed out the authentication for a service with REST calls but I am trying to proof out if it is still possible to use a C# SDK instead.
Question 2.
I found this article Azure Active Directory Graph Service Tutorial. After following the example I am able to create an HTTP POST call and return an access_token. My question is there a way to use this token in conjunction with the Microsoft Graph CSharp SDK or OneDrive CSharp SDK to serve as the authentication process?
Update:
Okay, I was able to proof out some more and having a working code, but I am now getting an error around {Code: InvalidAuthenticationTokenMessage: Access token validation failure.
I did the exact same call with Postman and was able to get data back with REST calls, is REST the only way to achieve this?
I created a gist for my attempt: Code
Solved
On line 62 in the gist, I was hitting the wrong resource. The correct resource is https://graph.microsoft.com
I need to write a console application to retrieve domain shared contacts (eventually update, add or delete them, too).
What I found so far is "Google Domain Shared Contacts API" should do just that, but I am a bit clueless as where to start.
I don't know how to access this API in .NET and I haven't found any examples of such a code.
As far as I can see in the documentation, Domain Shared Contacts API is not currently included in the list of Supported Google APIs for .NET .
You may, however, check in Release Notes for the Google API Client Library for .NET for announcement or updates regarding this API.
If the time comes that Domain Shared Contacts API becomes supported, you may use the following references to get started:
Easily access Google APIs from .NET
GitHub post - google-api-dotnet-client
GitHub post - google-api-dotnet-client-samples
I managed to come up with an application that sends http requests to the API, however their documentation is terrible as it lacks complete description of how exactly the requests should look like and I had to experiment a bit.
I'd like to use the Google Drive API in my C# desktop application. However, I've found the official Google SDK on NuGet to have more dependencies than I'm comfortable with (adding it to my VS2010 project adds 10 additional NuGet packages). I fear these dependencies will clash with other dependencies as my solution grows.
Is there an alternative to this approach that utilizes less dependencies?
Can I utilize a different OAuth 2.0 library or must I use Google's OAuth sdk? Is there anything special about Google's OAuth 2.0 implementation that would hinder the ability to use an alternative OAuth 2.0 library?
Is there an alternative to this approach that utilizes less dependencies?
You could certainly write your own API using the HttpClient combined with the Drive API. The API uses simple Get/Post/Put/Delete/Patch http methods to change files in the google drive.
Can I utilize a different OAuth 2.0 library or must I use Google's OAuth sdk?
Depends. If you wrote your own, then you can use (or write) any OAuth client. The http methods must include the OAuth information in the requests, so writing your own gives you that type of access.
If you are looking for an actual product recommendation, that would be an off topic question (do not ask #5) for stack overflow.
Update
Let talk about how OAuth works at a very very high level. Once the user authorizes your code to impersonate (for lack of better terminology), you get a Authorization Code, which you use to get an Exchange Token.
The Token is the important part. If a pre-build framework does not have any way for you to specify what the Token is it doesn't matter.
If you wanted to authenticate your request yourself, say using C#, when you make a call to access Google Drive API, you'd want to add the Authorization to the Google Headers (or QueryString, but I personally don't like to use the Querystring):
GET /plus/v1/people/me HTTP/1.1
Authorization: Bearer 1/fFBGRNJru1FQd44AzqT3Zg
Host: googleapis.com
Rolling your own is not too onerous.
All of the http calls are documented on this page https://developers.google.com/accounts/docs/OAuth2, in combination with the sub-page specific to your scenario (eg. embedded, web, etc).
Once you think you understand it, go to the excellent Oauth Playground at https://developers.google.com/oauthplayground/ and watch the http traffic.
Provided you can make http calls that match what you see in the playground, you're diamond.
Most of the effort is in handling the various states that your app may encounter:-
invalid grant (eg. Google expired the refresh token)
token expiration
timeouts
user declined auth
You have a choice at the http level. You can use C#'s http directly, or you could use the Google http libraries as mentioned by Erik.
I'd like to write a console program in C# that posts a Tweet to Twitter. I've never used the Twitter APIs before and don't know anything about how their authentication works. I found an API library called Twitterizer, but it seems geared towards web applications and wants the user to logon with a web browser. All the API docs on Twitter's website seems geared around this scenario as well.
Is it possible to access the Twitter APIs using a console app with no web browser access? I'm perfectly fine hard coding in the name and password for the Twitter user I want to post under as well. Thanks!
Mike
You'll need to use OAuth for authenticating in twitter.
Then use regular HTTP Request to use the twitter JSON-based API.
Here you can find a good article about OAuth, Twitter and console applications.
Also take a loot at linq2twitter lib. From it's documentation;
The Twitter API is built using
Representable State Transfer (REST).
Wikipaedia defines REST as "...a style
of software architecture for
distributed hypermedia systems...",
but I'm going to be so bold as to try
to simplify what that means. In
practice, REST is a Web service
protocol built upon Hypertext Transfer
Protocol (HTTP). You use the REST Web
service by making an HTTP call with a
URL and getting text back in some
form, which is often XML or JSON. So,
if you were to write code that made an
HTTP request with the following URL:
http://api.twitter.com/1/statuses/public_timeline.xml
You would get back an XML document
with all of the Twitter statuses from
the public timeline, which is a
snapshot in time of the last 20 tweets
at the time of your request. Go ahead
and open your browser, copy and paste
the URL above into the address bar,
and see what you get back.
I couldn't find any decent information on the web on how to do this, so I decided to write my own blog post with all the details.. Enjoy!
http://blog.kitchenpc.com/2011/01/22/rise-of-the-twitterbot/
of course you can use anything to connect to Twitter via RESTful api.
you should use oauth, and set up your application in http://dev.twitter.com, then you should read all articles listed in documents, you must specify your app as Client but not Browser so user input a number to get through authentication.
you can use many libraries so that you can save your time, all are listed in the documents
and be CAREFUL, you should not use Twitter's own api console which is buggy (as i know parameters somtimes can't be parsed), you should use APIgee instead which is powerful and stable.
if you want use basic authentication, you should use api proxy (one famous is twip), if you just need only one single C# apps, you must code by yourself:
you should use given username and password to login twitter, parse cookies passed
use normal oauth to get temporaly access token url.
use cookies got from step 1, emulates form submit to allow your apps, capture PIN code
use pin code to finish oauth.
MOST IMPORTANT, you must store access token in client's machine so next time you can bypass above steps
Just wrote a Twitter Bot in C#. This is currently posting tweets to #valuetraderteam.
https://gist.github.com/sdesalas/c82b92200816ecc83af1
The API component in the GIST below is less than 500 lines, only dependency is Json.NET, you'll need to download the latest DLL for either x64 or x86 (depending on what platform you are targetting) and include as a reference in your project.
There is an example at the bottom of the page of how you can make a tweet from a console application
Hopefully this is useful to some other people out there.