LibGit2Sharp fetching error "Too many redirects or authentication replays" - libgit2sharp

I receive the error “Too many redirects or authentication replays” when trying to fetch with libgit2sharp from a TFS server.
I've tried the solutions in the article below and none seem to be working.
LibGit2Sharp: Fetching fails with "Too many redirects or authentication replays"
code using DefaultCredentials():
CredentialsHandler credHandler = (_url, _user, _cred) => new DefaultCredentials();
var fetchOpts = new FetchOptions { CredentialsProvider = credHandler };
using (var repo = GetRepository())
{
Remote remote = repo.Network.Remotes["origin"];
repo.Network.Fetch(remote, fetchOpts);
} // using

Related

Microsoft Graph V1 API error: OData::ServerError 503 ConcurrentItemSave: "Conflicts occurred during saving data to store

I'm having trouble debugging the issue occurs when pushing new events to Outlook Calendar using Microsoft Graph API (v1). I have tested and it's still working, but I received this error which happened a few times today from my Ruby on Rails apps with the gems mentioned in the code snippet below. And there are duplicate events added to the calendar after these errors. I have searched this issue but still got nothing. Could anyone help me to debug this problem, please? I just don't know if this issue caused by my users' actions or just API server error. Many thanks!
OData::ServerError 503 ConcurrentItemSave: "Conflicts occurred during saving data to store (saveresult: IrresolvableConflict, properties: ). Please retry the request." from "https://graph.microsoft.com/v1.0/me/calendars/AAMkADg1YmMzNjE2LTM5Y2MtNGI2NC05NjJjLWRiY2RhZTZkNDRkMABGAAAAAADZc5aq6QclSqy_4oRMVv_EBwB4ZnW6S6xLTZDSXIsgJfprAAAAAAEGAAB4ZnW6S6xLTZDSXIsgJfprAAAGEcjmAAA=/events"
Code I use to create events via api
require 'adal'
require 'microsoft_graph'
username = ENV["OUTLOOK_USERNAME"]
password = ENV["OUTLOOK_PASSWORD"]
client_id = ENV["OUTLOOK_CLIENT_ID"]
client_secret = ENV["OUTLOOK_CLIENT_SECRET"]
tenant = ENV["OUTLOOK_TENANT"]
user_cred = ADAL::UserCredential.new(username, password)
client_cred = ADAL::ClientCredential.new(client_id, client_secret)
context = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
resource = "https://graph.microsoft.com/"
tokens = context.acquire_token_for_user(resource, client_cred, user_cred)
callback = Proc.new { |r|
r.headers["Authorization"] = "Bearer #{tokens.access_token}"
r.headers["Prefer"] = 'outlook.timezone="Australia/Sydney"'
r.headers['Content-type'] = 'application/json'
}
#graph = MicrosoftGraph.new(
base_url: "https://graph.microsoft.com/v1.0",
cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, "metadata_v1.0.xml"),
&callback
)
#example_data
calendar_id = "my_calendar_id"
data = my_event_object
#graph.service.post("me/calendars/#{calendar_id}/events", data.to_json)

Getting #Mention to work with a TFS Extension on TFS 2017.3

I am trying to programmatically add the mention of users that are members of groups in TFS in the discussion area of work items. We were using the 1.0 version with TFS 2017 update 2 with success:
#{id.DisplayName}
However upgrading to TFS 2017 update 3 fails to send emails on the notifications. We also tried all of the "user ids" we could find on the TeamFoundationIdentitiy object for the solutions found here:
VSTS - uploading via an excel macro and getting #mentions to work
So how can we get emails for #mentions to work again in TFS 2017.3?
Update: 9/11/2018
Verified service account fails to send emails while my account running the same code will send emails for mentions:
using (var connection = new VssConnection(collectionUri, cred))
using (var client = connection.GetClient<WorkItemTrackingHttpClient>())
{
var wi = new JsonPatchDocument
{
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.History",
Value = $"#{id.DisplayName} <br/>"
}
};
using (var response = client.UpdateWorkItemAsync(wi, workItemId, suppressNotifications: false))
{
response.Wait();
}
}
We solved by dropping use of the WorkItemHttpClient and going back to loading the SOAP WorkItemStore as the user that submitted the changes instead of the service account. It would be nice if we could use impersonation of a user with TFS's WebApi

OAuth2 authentication error using 'python-o365' library

I have able to successfully connect and read emails using the 'python-o365' library:
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
inbox = FluentInbox()
for message in inbox.fetch_next(2):
print(message.getSubject())
However, when I try to send an email using a more basic example, I am receiving a 401 response from the server.
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
att = Attachment(path=FilePath)
m = Message()
m.setRecipients(EmailTo)
m.setSubject('DBM Errors Identified - ' + FileName)
m.setBody(MessageBody)
m.attachments.append(att)
m.sendMessage()
I have also tried setting the connection object and passing it through as a parameter:
auth = Connection.oauth2('Client_ID','Client_Secret',store_token=True)
m = Message(*auth=auth*)
That however results in an error message of:
TypeError: 'Connection' object is not callable
Thanks for the help!
I was able to bypass the issue by switching to a fork of the 'python-o365' library that I used above. I feel like I am probably missing something obvious with that library but this solved the problem
Here is the simplified version of the authentication flow that I have working in case it interests anyone:
scopes = ['https://graph.microsoft.com/Mail.Read'']
account = Account(('Client_Id', 'Client_Secret'], auth_method='oauth',scopes=scopes)
account.connection.get_authroization_url() #generate the url for user to authenticate
result_url = input('Paste the result URL once you have authenticated...')
account.connection.get_session() #generate a session
m = account.new_message()
m.to.add('EmailTo')
m.body = 'MessageText'
m.send()

Google API Client Library freezing up in IIS when making request

I have been using the Google API Client Library for .NET for loading Google Analytics data into my application:
Recently though I have found it to have started freezing up completely. The Execute() command makes a connection to the Google server.
It makes a successful request to :
https://accounts.google.com/o/oauth2/token
which returns something like :
{
"access_token" : "ya30.HAKlQSGZo2GnK5wxlxx9TLTQUyD9Xkt7AZxuQnDY-KhJuCyrCtN_xHIP",
"token_type" : "Bearer",
"expires_in" : 3600
}
But then never returns from the Execute call.
The same code in a console app returns immediately, but in IIS it is currently never returning.
In a previous version it worked just fine (I'm not exactly sure which version it changed).
I have Load User Profile set to true.
What could be causing this?
var SERVICE_ACCOUNT_PKCS12_FILE_PATH = #"C:\TEMP\GoogleAnalytics-privatekey.p12";
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
// Create credentials (not my real login here)
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("86987278011-ctegcus4og7kn6oigkrv8po5pf67bbgj#developer.gserviceaccount.com")
{
Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
}.FromCertificate(certificate));
// Create the service
var service = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Google Analytics Application",
});
// get accounts
accounts = service.Management.Accounts.List();
var items = accounts.Execute();
As explained in Google Calendar API - Not Returning From Execute() C#, we currently have a bug in the latest version of Google.Apis.Auth v 1.9.3.
We already have a fix for it, in our repository (https://github.com/google/google-api-dotnet-client), so you can test it yourself with the Analytics API (https://developers.google.com/resources/api-libraries/download/analytics/v3/csharp).
A new release of the library is planned to be in the next few weeks so stay tuned - http://google-api-dotnet-client.blogspot.com/
Update (Dec 15th): New NuGet packages for 1.10.0 are available, read more about it at: http://google-api-dotnet-client.blogspot.com/2015/12/announcing-release-of-1100.html

Passing Authentication from WebApp to WebAPI using BreezeJS

I am having two web applications, one a SPA using AngularJS + BreezeJS and the other a WebAPI. We are building authorization in the WebAPI and the results get filtered based on user access. We want the user to sign-in into organization Azure AD in the SPA and pass the same authentication to WebAPI.
I am using ADAL JS library for authentication in SPA and have successfully handled that. However, I am not able to pass the same authentication to WebAPI using BreezeJS. Our WebAPI is OData v3 and without authn, Breeze works fine. We have customized the defaultHttpClient to add customer headers for DataVersion and MaxDataVersion since DataJS needs it.
var oldClient = OData.defaultHttpClient;
var myClient = {
request: function (request, success, error) {
request.headers.DataServiceVersion = '3.0';
request.headers.MaxDataServiceVersion = '4.0';
return oldClient.request(request, success, error);
}
};
OData.defaultHttpClient = myClient;
However, I am not sure how to pass authentication token.
I have done following in entityManager
var ajaxAdapter = breeze.config.getAdapterInstance("ajax");
ajaxAdapter.defaultSettings = {
xhrFields: {
withCredentials: true
}
};
as per the comments by Ward Bell on one of the posts by John Papa. However, this does not seem to be working. Need help.
Thanks
Hemant
After some tinkering with the HTTP requests, I found out that the Bearer token that we were expecting to be passed on to server was actually not happening. Reason being we were not using ajaxAdapter in breeze. We had to add that header ourselves and send the request. We had setup an application in Azure AD. We had to pickup the key for the client application to get the token from storage. This prefixed with "Bearer " did the trick. Here is the sample code for custom adapter:
var oldClient = OData.defaultHttpClient;
var myClient = {
request: function (request, success, error) {
request.headers.DataServiceVersion = '3.0';
request.headers.MaxDataServiceVersion = '3.0';
request.headers.Authorization = "Bearer " + adalAuthenticationService.getCachedToken('<<your AD client app key here>>');
return oldClient.request(request, success, error);
}
};
OData.defaultHttpClient = myClient;

Resources