I was try to connect my TFS server using my credentials . But i am getting error 'Basic authentication requires a secure connection to the server.'
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(basicAuthCredential)
{
AllowInteractive = false
};
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), tfsClientCredentials);
tfs.EnsureAuthenticated();
My tfs didn't have the https. Any alternative to fix it But browser level it is working fine
The BasicAuthCredential requires https://, I believe, and I wasn't able to access my TFS with https://. So I found another way to get from NetworkCredential to VssCredentials.
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
//BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredential);
VssCredentials vssCred = new VssClientCredentials(winCred);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), vssCred);
tfs.EnsureAuthenticated();
Try using the following code:
String collectionUri = "http://localhost:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
Related
i have to do the following: my documents are stored on a server. The only path i'm getting is an URI
I was trying to get the document but i'm keep getting a "403 Forbidden".
string[] myArray = context.Request.QueryString["ItemsArray"].Split(',');
MailMessage m = new MailMessage(new MailAddress("bart#schelkens.be"),
new MailAddress("bart#schelkens.be")
);
m.Subject = "Emailing documents";
foreach (string path in myArray)
{
using (WebClient wb = new WebClient())
{
wb.UseDefaultCredentials = false;
wb.Credentials = new NetworkCredential(_userName, _passWord);
var stream = wb.OpenRead(path);
m.Attachments.Add(new Attachment(stream, ""));
}
}
string mailBody = "Dear<BR/> Please find attached a new version of the documents.";
mailBody += "<BR/>";
m.Body = mailBody;
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("hybrid.kaneka.be");
smtp.EnableSsl = false;
smtp.Send(m);
Or is there another way to get my document from the website and then mail it?
In SharePoint I created my own button which, using a js-file, goes to my ashx to mail my documents.
Try to add the following line before opening the stream:
wb.Headers.Add("User-Agent: Other");
It could be, that it's forbidden because your server doesn't think, that you are a trusted client and blocks all connections without a User-Agent.
[edit 1]
If you try to download a file from SharePoint you have to use the SharePointOnlineCredentials from the SharePoint Server 2013 Client Components SDK:
Somewhere you have to define the credentials:
const string username = "username";
const string password = "password";
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
var credentials = new SharePointOnlineCredentials(username, securedPassword);
After that you can user this credentials in your WebClient:
wb.Credentials = credentials;
[edit 2]
If your on in an on-premises environment than you could use NetworkCredentials. Try to use the following:
wb.Credentials = new NetworkCredential("DOMAINNAME\username", "password");
[edit 3]
Maybe your server wants a real User-Agent. Because if something is wrong with your credentials there would be a 401 (unauthorized). For example try:
wb.Headers.Add("user-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
Provide the READ/WRITE rights/permission on the folder where your document is located.
Currently there is no read/write rights/permission on that folder that's why when ever you try to attach the document it returns 403 Forbidden error.
I am trying to connect online TFS using WCF service but it is throwing me exception "TF30063: You are not authorized to access https://abdul-r.visualstudio.com/DefaultCollection/TestTFS.".
Below is my sample code
NetworkCredential netCred = new NetworkCredential(
"*MyEmail*",
"*MyPassword*");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials credential = new TfsClientCredentials(basicCred);
credential.AllowInteractive = false;
string TFSServerPath = "https://abdul-r.visualstudio.com/DefaultCollection/TestTFS";
using (TfsTeamProjectCollection tfs1 = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
{
tfs1.EnsureAuthenticated();
}
Any help would be appreciated.
I have local tfs 2012. On Visual studio 2012 , use c# , I write program which programmatically connect to tfs server. But I have error:
{"TF30063: You are not authorized to access http://server:8080/tfs."} System.Exception {Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException}
My code:
Uri collectionUri = new Uri("http://server:8080/tfs");
NetworkCredential netCred = new NetworkCredential("login","password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred);
teamProjectCollection.EnsureAuthenticated();//throw error here
Can you help me fix this error?
P.S. I try do connect this way, but I have same error:
var projectCollection = new TfsTeamProjectCollection(
new Uri("http://myserver:8080/tfs/DefaultCollection"),
new NetworkCredential("youruser", "yourpassword"));
projectCollection.Connect(ConnectOptions.IncludeServices);
And this way:
Uri collectionUri = new Uri("http://server:8080/tfs/DefaultCollection");
NetworkCredential netCred = new NetworkCredential("login","password","Server.local");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred);
teamProjectCollection.EnsureAuthenticated();
Hope it helps you.
var tfsCon = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://server:8080/tfs"));
tfsCon.Authenticate();
var workItems = new WorkItemStore(tfsCon);
var projectsList = (from Project p in workItems.Projects select p.Name).ToList();
or
Uri TfsURL = new Uri(""http://server:8080/tfs"");
NetworkCredential credential = new NetworkCredential(Username, Password, Domain);
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(TfsURL, credential);
collection.EnsureAuthenticated();
If fails here you need to configure in App.config to set the default proxy:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>
</configuration>
I saw one artcle how to share our status in LinkedIn using c#.
I follow those steps and the code I am using is following...
For this I am using Hammock library.
OAuthCredentials credentials = new OAuthCredentials();
credentials.Type = OAuthType.AccessToken;
credentials.ConsumerKey = "****";
credentials.ConsumerSecret = "*****";
credentials.Token = "******";
credentials.TokenSecret = "*********";
credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1;
credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader;
RestClient client = new RestClient();
client.Authority = "http://api.linkedin.com/v1";
client.Credentials = credentials;
client.Method = WebMethod.Put;
byte[] msg = Encoding.Default.GetBytes("Test");
client.AddHeader("Content-Type", "text/xml");
client.AddPostContent(msg);
RestRequest request = new RestRequest();
request.Path = "http://api.linkedin.com/v1/people/~/current-status";
/* ERROR */ RestResponse response = client.Request(request);
It's giving me a error "Bad Request."
How to solve this please help me..?
I have to assign the username and password from credential cache to Httpwebrequest.When i assign to cache it is working but when assigning to Webrequest from cache it shows null. Where i'm wrong?
string strServer = "";
strServer = "http://servername/";
Uri uri = new Uri(strServer);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));
request.Credentials = cache;
Hello,
You just need to retrieve the credential from the cache, and then add it to the web request, example bellow:
cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));
NetworkCredential currentCredentials= cache.GetCredential(new Uri(strServer), "Basic"); //Get specific credential
request.Credentials = currentCredentials; //Allocate credential