I am trying to use the .NET APIs from Google
https://code.google.com/p/google-api-dotnet-client/
https://www.nuget.org/packages/Google.Apis.Authentication/
As most of these APIs from Google require an oAuth token for you to fetch any data from them, I am struggling to get over this first hurdle.
My plan is to create a very simple .NET Web API that lists out my Google Analytic's accounts via the API which I can then in turn use with AngularJS to bind to a nice little view with the JSON returned from my WebAPI call.
The problem I mentioned is that there seems to be lots of different examples floating about and I can't seem to get any to to work. Either its out of date or the sample project doesn't compile etc...
From what I can understand I need to pass an Authenticator object to the BaseClient object which is in turn used for any Service API.
Below is a rough example I am trying to get to work, but currently fails and gets an error back from Google's API because I am not logged in/passing an oAuth token. Can anyone give me any pointers or advice please.
Thanks, Warren
[HttpGet]
public IEnumerable<Account> GetAccounts()
{
var baseClient = new BaseClientService.Initializer();
baseClient.ApplicationName = "Google Stats Example";
baseClient.Authenticator = null; //Unsure how to get the oAuth token
AnalyticsService stats = new AnalyticsService(baseClient);
var accounts = stats.Management.Accounts.List();
var allAccounts = accounts.Execute();
return allAccounts.Items;
}
To create an authenticator you need a nuget package named "Google APIs OAuth2 Client Library" but i downloaded a nugget package named "Google.Apis.Oauth2.v2 Client Library". Similar names but not the same.
I was not able to find the correct one on nugget page. If you perform a search on that package it wont show up. I had to use Visual Studio Nugget searcher and activate "show prerealese packages" to install it.
Related
As shown in https://petstore.swagger.io/, apis of the PET controller get authenticated by OAuth2, but that of the STORE controller, gets authenticated by ApiKey.
I want to achieve the same using IOperationFilter in .Net MVC (and not .Net Core).
Though I am able to turn on the BasicAuth for one API, but couldn't turn off the ApiKey Auth for the same. May be I am not able to find the correct documentation of using the tool.
Could someone point me towards the correct documentation please.
Swagger-Net version 8.3.35.101
I've question regarding automation with oAuth 1.0a. I need to access a REST API at a oAuth provider on behalf of a user. The provider has oAuth version 1.0a implemented.
At forehand excuse my ignorance on oAuth, it's new territory for me.
I'm working on a .NET MVC 5 project and installed the NuGet Package as follows: "Install-Package DotNetOpenAuth.OAuth.Consumer". This installed the following:
Attempting to gather dependencies information for package 'DotNetOpenAuth.OAuth.Consumer.4.3.4.13329' with respect to project 'projectname', targeting '.NETFramework,Version=v4.6.1'... successfully installed dependencies and the DotNetOpenAuth consumer package.
My goal is to access a REST API when triggered by an external source which is not human. In short, a controller is triggered by an external process and sends data to my application. Next, I will need to access the REST API of the provider in order to process the received data. So, no human eyes or hands are available to login or copy a verifier of some sort.
I've been looking around, read about oAuth and the DNOA library. I kinda found that I have to obtain a RequestToken to start off with. I'm using the following code to achieve this:
InMemoryTokenManager tm = new InMemoryTokenManager("**consumerkey**", "**secret**");
var serviceProvider = GetServiceDescription();
var consumer = new DesktopConsumer(serviceProvider, tm);
string reqToken;
consumer.RequestUserAuthorization(null, null, out reqToken);
I read about the InMemoryTokenManager, ServiceProviderDescription, DesktopConsumer and that is pretty clear to me. Although I'm not surefooted about using DesktopConsumer instead of WebConsumer..
Now, I need to get a verification code from the Provider. But how to proceed next in order to get it?
I've looked at the UserAuthorizationResponse object which contains a property exactly for this purpose but I'm unable to figure out how to retrieve this.
With the request token and verification code I should be able to get a AuthorizedTokenResponse object and perform the REST API calls.
Can anyone help me out on this?
I have an ASP.NET MVC website in which I have added a "Web API 2 OData Controller with Actions, using Entity Framework".
This is the 1st set of code that is auto-generated.
I am calling this web API from a native client. I have added a reference to the Web API service through, Right Click, Add References.
This is the 2nd bit that is auto-generated.
I've configured Azure AD authentication at the client side. This is working.
What I want to do now is: setup authentication for each Web API call based on the user who logged in from the client. So the client's access token needs to be passed from the client to the Web API, and this token should be used to authenticate further.
Note that a lot of the code is auto-generated. So the additions to code should have minimal effect on regeneration of the code, if possible.
Later on the Web API will use the user information to filter data based on his identity, and use role based identity as well.
Any pointers on how to start with this? I feel that all the various pieces are available, but how to gather them into a single solution is just out of grasp.
The container that is part of the auto-generated solution is where we need to pass the token.
Here's the code:
autogenContainer.BuildingRequest += (sender, args) =>
{
args.Headers.Add("Authorization", "Bearer " + access token retrieved from Azure);
};
I'm trying to create a redistributable web application that will integrate with Google Analytics through the Google Reporting API. Customer will install the application on their server.
I'm following this tutorial (I'm using PHP, but I believe this is not of importance for my question)
https://developers.google.com/analytics/resources/tutorials/hello-analytics-api
This works fine. No issues there.
However I can't figure out one missing element:
The tutorial starts with sending me to the Google APIs console where I have to create and configure a new API project and create and configure a client ID.
That's a lot of work that requires fairly technical knowledge (redirect url, selecting correct API, error-prone copy-and-pasting, etc.)
So my questions:
Is there an API so I can programmatically set this up for my user?
If that's not possible, is there a more user-friendly way to obtain Analytics reporting that is future-proof? (I noticed they are currently deprecating a few older APIs)
Unfortunately that's AFAIK not possible.
You could go one of the following ways:
Move client_id and client_secret to some configuration file and help your customer with deployment.
Show a one-time setup wizard for your app and guide your customer step-by-step. There you can at least provide him with the right callback URLs.
Regard your application as "installed application" and instrument curl or something similar for sending the requests.
I'm new to oAuth.
What I need to do is
a) the user logs in the site using default .net membership provider
b) once he logs in he links his google/yahoo account ( what I understand is he gets a token access which should preferably never expire and I keep it in my db)
c) the user can get his google/yahoo contacts (Name, email id and if possible a unique id for each contact) using the token access
I have created a google account and have the app id and secret key.
I'm looking at dotnetopenauth samples, project templates and tools but it has lots of things and I would appreciate if someone can guide me on the right path.
Thanks and best regards
Arnab
The OAuthConsumer sample, GoogleAddressBook.aspx page, shows how to pull Google Contacts using OAuth. Note that although this sample is in web forms rather than MVC, the OAuth consumer code is entirely written in the code-behind and has no web forms-specific stuff in it, so it can be easily lifted and dropped into an MVC app without issue.
There is no equivalent Yahoo! sample that ships as part of DotNetOpenAuth.
Don't try to use the InMemoryTokenManager that the sample uses. Write your own ITokenManager implementation. The comments and docs will guide you.