Retrieving Profiles and connections - Parameter missing? - c#

I use Google's .NET people API (v.1.25) and follow the documentation (https://developers.google.com/people/v1/read-people).
Under
Retrieve Profiles and Connections
Get the user's connections
for .NET the documentation gives this example code snippet:
PeopleResource.ConnectionsResource.ListRequest peopleRequest =
peopleService.People.Connections.List("people/me");
peopleRequest.PersonFields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Person> connections = connectionsResponse.Connections;
But PersonFields do not exist in the class ListRequest - nor does it exist in GetRequest as the doc suggests in the next example.
Do I misunderstand something or is there a fault in the docs or in the API?

It seems like you are using an old version of the library. If you browse the .NET documentation from the Install Client Libraries page it shows the version is 1.5.1.
If you browse to the ConnectionsResource.ListRequest documentation it shows that PersonFields exists.

Just use .Fields instead of .PersonFields. Also I had to declare the entire package name (Google.Apis.People.v1.). Example below.
Google.Apis.People.v1.People.PeopleService peopleService;
Google.Apis.People.v1.PeopleResource.ConnectionsResource.ListRequest peopleRequest = peopleService.People.Connections.List("people/me");
peopleRequest.Fields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Google.Apis.People.v1.Data.Person> connections = connectionsResponse.Connections;
Hope this helps.

Related

Convert a Kerberos based WindowsIdentity into a Base64 string

If I have the following code:
var token = System.Security.Principal.WindowsIdentity.GetCurrent();
I get a WindowsIdentity that is Kerberos based. I need to make a call with a header like this:
Authorize: Negotiate <Kerberos Token Here>
Is there a way to convert that token object into a Base64 string?
As the maintainer of the Kerberos.NET as mentioned in the other answer, you can always go that route. However, if you want SSO using the currently signed in Windows identity you have to go through Windows' SSPI stack.
Many .NET clients already support this natively using Windows Integrated auth, its just a matter of finding the correct knobs. It's unclear what client you're using so I can't offer any suggestions beyond that.
However if this is a custom client you have to call into SSPI directly. There's a handful of really good answers for explaining how to do that such as: Client-server authentication - using SSPI?.
The aforementioned Kerberos.NET library does have a small wrapper around SSPI: https://github.com/dotnet/Kerberos.NET/blob/develop/Kerberos.NET/Win32/SspiContext.cs
It's pretty trivial:
using (var context = new SspiContext($"host/yourremoteserver.com", "Negotiate"))
{
var tokenBytes = context.RequestToken();
var header = "Negotiate " + Convert.ToBase64String(tokenBytes);
...
}
I could not get this to work, but I was able to get a token using the excellent Kerberos.NET NuGet package. With that I was able to get it like this:
var client = new KerberosClient();
var kerbCred = new KerberosPasswordCredential("UserName", "p#ssword", "domain");
await client.Authenticate(kerbCred);
Console.WriteLine(client.UserPrincipalName);
var ticket = await client.GetServiceTicket("http/ServerThatWantsTheKerberosTicket.domain.net");
return Convert.ToBase64String(ticket.EncodeGssApi().ToArray());
As an aside, I needed help figuring out what the SPN value was for the GetServiceTicket and the project maintainer was fantastically helpful (and fast!).

Nuget api issue

I need to automatically collect the information from the nuget packages of a series of projects. For this purpose I use the API that miscrosoft makes available.
Making the call:
https://api.nuget.org/v3/registration3/epplus/index.json
I get the most recent version: v.4.5.3.1 while on the nuget website it is: v. 5.1.2.
To make the call I use the following code:
static void GetNuGetIndex(Model.Package package)
{
string uri = "https://api.nuget.org/v3/registration3/" + package.Name.ToLower() + "/index.json";
string json = new WebClient().DownloadString(uri);
var packageIndex = JsonConvert.DeserializeObject<JSONModel.NuGetPackageIndex>(json);
int packageIndexItemCounter = 0;
if (packageIndex.Items.Count > 0)
foreach (var packageItem in packageIndex.Items)
{
packageIndexItemCounter++;
List<JSONModel.NuGetPackageItem> items = packageItem.Items;
if (packageItem.Items == null)
{
string lookupjson = new WebClient().DownloadString(packageItem.LookupUrl);
items = JsonConvert.DeserializeObject<JSONModel.NuGetPackageItems>(lookupjson).Items;
}
GetNuGetItems(package, items, package.Name, package.Version, (packageIndexItemCounter.Equals(packageIndex.Items.Count) ? packageItem.Upper : "" ));
}
}
Can anyone give me an explanation of why I have this problem and how can it be solved?
Thanks
I believe this is because this endpoint has been discontinued.
Consulting to the service index api, available at: https://api.nuget.org/v3/index.json (DOC) you can see that the address you are using is not returned.
When consulting the endpoint https://api.nuget.org/v3/registration5-semver1/epplus/index.json provided by the index api, the "upper" field will now return the most current version
I looked here, which suggests you need a different query to return packages:
https://api.nuget.org/v3/registration5-semver1/epplus/index.json
As Kelvin mentioned, that registration hive has been discontinued. I would recommend using the NuGet client SDK to interact with the NuGet API: https://learn.microsoft.com/en-us/nuget/reference/nuget-client-sdk#list-package-versions
If you still would like to use the NuGet APIs directly, I recommend reading through the following resources:
https://learn.microsoft.com/en-us/nuget/api/overview
https://learn.microsoft.com/en-us/nuget/api/service-index
https://learn.microsoft.com/en-us/nuget/api/registration-base-url-resource
TLDR: You have to "discover" the latest location of the registration endpoint using the V3 Service Index API at https://api.nuget.org/v3/index.json.

YouTrackSharp: can't get it to work

Trying to open an issue from a C# app.
Few issues:
1) UPDATE: I realize it only supports .NET Standard 1.3 = Framework 4.6; So no issue here.
2) I install version 2.0.31 (and less) - When I try to set up a connection, it says "Method not allowed":
var connection = new Connection("xxxx.myjetbrains.com", 80, false, "youtrack");
connection.Authenticate("xxxxx", "xxxxxx");
var issueManagement = new IssueManagement(connection);
dynamic issue = new Issue();
issue.Assignee = "xxxxx";
issue.ProjectShortName = "CV";
issue.Type = "Bug";
issue.Summary = "Test";
issue.Description = "Testing 1 2 3 ...";
issueManagement.CreateIssue(issue);
connection.Authenticate throws the error.
3) If I don't specify other parameters in Connection and leave only the basic url, I get the following error (again in connection.Authenticate):
For security reasons DTD is prohibited in this XML document. To enable
DTD processing set the DtdProcessing property on XmlReaderSettings to
Parse and pass the settings into XmlReader.Create method.
Can't seem to find much info on this online. Anyone has any idea what to do?
the 1.3 refers to .NETStandard - NOT .Net Framework. These are not the same thing.
You need .Net Framework 4.6 or up for .Net Standard 1.3 compatibility.
See here:
https://learn.microsoft.com/en-us/dotnet/standard/net-standard
I'd go directly to jetbrains for the other parts...
For anyone else getting stuck:
my YouTrack account was like this:
https://mycompanyname.myjetbrains.com/youtrack
Since it uses SSL (i.e. https) I had to mark the SSL parameter true instead of false, and mark port 443 instead of 80. Also I had to add the "youtrack" as a parameter. So the end result looks like this:
var connection = new Connection("xxxx.myjetbrains.com", 443, true, "youtrack");
connection.Authenticate("xxxx#xxxx.xxx", "xxxx");
I only had to do this in v.2, as I mentioned, v.3.0.0+ has working examples in their blog.

Skybrud social Log in via Facebook?

I'm usinng skybrud social to allow users to log into my site via Facebook, but am having a problem.
For some reason, the response never contains anything other than the Name and Id of the user... everything else is null.
var url = client.GetAuthorizationUrl(state, "public_profile", "email");
var service = FacebookService.CreateFromAccessToken(userAccessToken);
FacebookMeResponse user = service.Methods.Me();
Has anyone experienced this before? What could be the problem?
Facebook has multiple versions of their Graph API. In the most recent version (2.4), less fields are returned by default, and you instead have to tell the API to return the fields that you need. What version of the API you're using depends on the time you registered your app with Facebook.
Based on your code, it seems that you're using an older version of Skybrud.Social. If you update to the most recent version (0.9.4.1), you can do something like this:
// Declare the options for the call to the API
FacebookGetUserOptions options = new FacebookGetUserOptions("me") {
Fields = "name,email,gender"
};
// Make the call to the API
FacebookUserResponse response = service.Users.GetUser(options);
Hope this answers your questions ;)

.NET Toolkit for Rally REST API Documentation deprecated?

I'm starting to work with Rally .NET API, in order to develop a plugin to import User Story into Enterprise Architect.
I have started by the examples in the following page: http://developer.help.rallydev.com/rest-api-net.
In the last one, for example, I got this errors:
//Create an item
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate["Name"] = "My Defect";
CreateResult createResult = restApi.Create("defect", toCreate);
Error 1 No overload for method 'Create' takes 2 arguments
//Delete the item
OperationResult deleteResult = restApi.Delete(createResult.Reference);
Error 2 No overload for method 'Delete' takes 1 arguments
But the documentation here is different from the examples.
All in all, I would like to know any good sources of information to learn this Rally API and which is the correct implementation for the Create and Delete in the examples of the first page.
Thanks in advance,
Pedro
Sorry for the confusion - with the latest release of the .NET REST DLL (version 1.0.15), both the Create and Delete methods changed slightly - they now require a Workspace Ref:
String workspaceRef = "/workspace/12345678910";
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate["Name"] = "My Defect";
CreateResult createResult = restApi.Create(workspaceRef, "defect", toCreate);
Delete should look like this:
OperationResult deleteResult = restApi.Delete(workspaceRef, createResult.Reference);
Or this:
myDefectObjectID = "12345678911";
OperationResult deleteResult = restApi.Delete(workspaceRef, "Defect", myDefectObjectID);
We'll work to get the documentation updated as quickly as possible. Thanks for pointing this out!

Categories