0
我需要通過OAuth2
連接WebService
中的VS-Team-Services。
我在官方網站上發現了sample solution,但我無法修改它在我們的Web服務代碼中使用它。
因爲它在請求訪問令牌時請求許可Accept or Deny
。
我需要它自動授予訪問沒有權限頁的令牌。通過Asp.Net WebForms訪問VS-Team Services OAuth
這是我以前的工作代碼沒有OAuth。我需要根據OAuth修改此代碼。
private Dictionary<string, MyTfsTeamProjectCollectionHelper> GetTFSProjectCollections()
{
try
{
TFSConnectionProviderHelper connect = new TFSConnectionProviderHelper();
ICredentials iCred = new NetworkCredential(strTFSUsername, strTFSPassword);
connect.GetCredentials(new Uri(ConfigurationManager.AppSettings["ServerURL"]), iCred);
TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(ServerURL), connect);
configurationServer.EnsureAuthenticated();
ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
DictionaryTfsTeamProjectCollection = new Dictionary<string, MyTfsTeamProjectCollectionHelper>();
foreach (CatalogNode tpcNode in collectionNodes)
{
MyTfsTeamProjectCollectionHelper myTfsTeamProjectCollection = new MyTfsTeamProjectCollectionHelper();
Guid tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection tfsTeamProjectCollection = configurationServer.GetTeamProjectCollection(tpcId);
myTfsTeamProjectCollection.TfsTeamProjectCollection = tfsTeamProjectCollection;
DictionaryTfsTeamProjectCollection.Add(tfsTeamProjectCollection.Name.Replace(tfsTeamProjectCollection.ConfigurationServer.Name.ToString() + "/", "").ToLower(), myTfsTeamProjectCollection);
}
return DictionaryTfsTeamProjectCollection;
}
catch (Exception ex)
{
Logger.WriteToLog(Logger.LogType.Error, strFlow, strCaseno, strTFSID, strUser, ex.Message);
Logger.WriteToLog(Logger.LogType.Error, strFlow, strCaseno, strTFSID, strUser, " StackTrace: " + ex.StackTrace);
return null;
}
}
private Project GetTFSProject(string tfsProjectCollectionName, string StrTFSProject)
{
try
{
GetTFSProjectCollections();
Project project = null;
if (DictionaryTfsTeamProjectCollection != null && DictionaryTfsTeamProjectCollection.Keys.Contains(tfsProjectCollectionName.ToLower()))
{
TfsTeamProjectCollection myTeamProjectCollection = DictionaryTfsTeamProjectCollection[tfsProjectCollectionName.ToLower()].TfsTeamProjectCollection;
WorkItemStore workItemStore = myTeamProjectCollection.GetService<WorkItemStore>();
project = (from Project pr in workItemStore.Projects select pr).ToList().Where(i => i.Name.ToLower() == StrTFSProject.ToLower()).SingleOrDefault();
}
else
{
Logger.WriteToLog(Logger.LogType.Error, strFlow, strCaseno, strTFSID, StrTFSProjectcollection, "ProjectCollectionName does not exist:" + tfsProjectCollectionName);
}
return project;
}
catch (Exception ex)
{
Logger.WriteToLog(Logger.LogType.Error, strFlow, strCaseno, strTFSID, strUser, ex.Message);
Logger.WriteToLog(Logger.LogType.Error, strFlow, strCaseno, strTFSID, strUser, " StackTrace: " + ex.StackTrace);
return null;
}
}
權限頁面的屏幕截圖:
我們是一個WebForms
模板。是否可以通過簡單的Asp.Net Webforms模板訪問VSTS OAuth模板?
**有VSTS OAuth模板的Asp.Net Webforms ** - 是否有樣本?如果是的話,請你指出正確的方向。 –
對不起,我的意思是沒有.... –