Enable authenticated calls in SimpleApi

Move windows credential store code to its own project so both the
regular api code and the SimpleApi (lightweight calls for the home
section and nav items) can use it.
This commit is contained in:
Andreia Gaita 2015-04-15 15:54:36 +02:00
Родитель de9ef09b2c
Коммит 2bd96207e8
19 изменённых файлов: 206 добавлений и 27 удалений

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
VisualStudioVersion = 14.0.22809.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.VisualStudio", "src\GitHub.VisualStudio\GitHub.VisualStudio.csproj", "{11569514-5AE5-4B5B-92A2-F10B0967DE5F}"
EndProject
@ -94,6 +94,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat-Net45", "submodules\s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat-Portable", "submodules\splat\Splat\Splat-Portable.csproj", "{0EC8DBA1-D745-4EE5-993A-6026440EC3BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CredentialManagement", "src\CredentialManagement\CredentialManagement.csproj", "{41A47C5B-C606-45B4-B83C-22B9239E4DA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -328,14 +330,13 @@ Global
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|x86.ActiveCfg = Debug|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|x86.Build.0 = Debug|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|Any CPU.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|x86.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|x86.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|Any CPU.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|x86.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|x86.Build.0 = Release|Any CPU
{252CE1C2-027A-4445-A3C2-E4D6C80A935A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{252CE1C2-027A-4445-A3C2-E4D6C80A935A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{252CE1C2-027A-4445-A3C2-E4D6C80A935A}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{252CE1C2-027A-4445-A3C2-E4D6C80A935A}.Debug|Any CPU.Build.0 = Release|Any CPU
{252CE1C2-027A-4445-A3C2-E4D6C80A935A}.Debug|x86.ActiveCfg = Debug|Any CPU
@ -358,18 +359,18 @@ Global
{0EC8DBA1-D745-4EE5-993A-6026440EC3BF}.Release|Any CPU.Build.0 = Release|Any CPU
{0EC8DBA1-D745-4EE5-993A-6026440EC3BF}.Release|x86.ActiveCfg = Release|Any CPU
{0EC8DBA1-D745-4EE5-993A-6026440EC3BF}.Release|x86.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|Any CPU.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|x86.ActiveCfg = Debug|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Debug|x86.Build.0 = Debug|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|Any CPU.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|x86.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Publish|x86.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|Any CPU.Build.0 = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|x86.ActiveCfg = Release|Any CPU
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64}.Release|x86.Build.0 = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Debug|x86.ActiveCfg = Debug|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Debug|x86.Build.0 = Debug|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Publish|Any CPU.Build.0 = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Publish|x86.ActiveCfg = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Publish|x86.Build.0 = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Release|Any CPU.Build.0 = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Release|x86.ActiveCfg = Release|Any CPU
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -389,9 +390,9 @@ Global
{1E7F7253-A6AF-43C4-A955-37BEDDA01AC9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
{B4E665E5-6CAF-4414-A6E2-8DE1C3BCF203} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC9}
{241C47DF-CA8E-4296-AA03-2C48BB646ABD} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC9}
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC9}
{1E7F7253-A6AF-43C4-A955-37BEDDA01AF9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
{252CE1C2-027A-4445-A3C2-E4D6C80A935A} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AF9}
{0EC8DBA1-D745-4EE5-993A-6026440EC3BF} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AF9}
{EB73ADDD-2FE9-44C0-A1AB-20709B979B64} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AC9}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{41A47C5B-C606-45B4-B83C-22B9239E4DA0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CredentialManagement</RootNamespace>
<AssemblyName>GitHub.CredentialManagement</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\script\Key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
</PropertyGroup>
<ItemGroup>
<Reference Include="NullGuard, Version=1.4.1.0, Culture=neutral, PublicKeyToken=1958ac8092168428, processorArchitecture=MSIL">
<HintPath>..\..\packages\NullGuard.Fody.1.4.1\Lib\portable-net4+sl4+wp7+win8+MonoAndroid16+MonoTouch40\NullGuard.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\script\Key.snk">
<Link>Key.snk</Link>
</None>
<Compile Include="..\..\script\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Credential.cs" />
<Compile Include="CredentialSet.cs" />
<Compile Include="CredentialType.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="PersistenceType.cs" />
<Compile Include="SecureStringHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitHub.Extensions\GitHub.Extensions.csproj">
<Project>{6afe2e2d-6db0-4430-a2ea-f5f5388d2f78}</Project>
<Name>GitHub.Extensions</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Fody.1.28.0\build\Fody.targets" Condition="Exists('..\..\packages\Fody.1.28.0\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Fody.1.28.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Fody.1.28.0\build\Fody.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using GitHub.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<NullGuard ExcludeRegex="^GitHub.Authentication.CredentialManagement.*$"/>
</Weavers>

Просмотреть файл

@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("GitHub.CredentialManagement")]
[assembly: AssemblyDescription("GitHub CredentialManagement")]
[assembly: Guid("41a47c5b-c606-45b4-b83c-22b9239e4da0")]

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fody" version="1.28.0" targetFramework="net452" userInstalled="true" />
<package id="NullGuard.Fody" version="1.4.1" targetFramework="net452" userInstalled="true" />
</packages>

Просмотреть файл

@ -41,7 +41,7 @@
<AssemblyOriginatorKeyFile>..\..\script\Key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
@ -54,6 +54,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SimpleCredentialStore.cs" />
<None Include="..\..\script\Key.snk">
<Link>Key.snk</Link>
</None>
@ -71,6 +72,10 @@
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
<Name>Octokit</Name>
</ProjectReference>
<ProjectReference Include="..\CredentialManagement\CredentialManagement.csproj">
<Project>{41a47c5b-c606-45b4-b83c-22b9239e4da0}</Project>
<Name>CredentialManagement</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Exports\GitHub.Exports.csproj">
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
<Name>GitHub.Exports</Name>

Просмотреть файл

@ -30,6 +30,7 @@ namespace GitHub.Api
this.enterpriseProbe = enterpriseProbe;
this.wikiProbe = wikiProbe;
this.OriginalUrl = repoUrl;
}
public async Task<Repository> GetRepository()

Просмотреть файл

@ -27,7 +27,7 @@ namespace GitHub.Api
{
var hostAddress = HostAddress.Create(repoUrl);
var apiBaseUri = hostAddress.ApiUri;
return new SimpleApiClient(hostAddress, repoUrl, new GitHubClient(productHeader, apiBaseUri), lazyEnterpriseProbe, lazyWikiProbe);
return new SimpleApiClient(hostAddress, repoUrl, new GitHubClient(productHeader, new SimpleCredentialStore(hostAddress), apiBaseUri), lazyEnterpriseProbe, lazyWikiProbe);
}
}
}

Просмотреть файл

@ -0,0 +1,59 @@
using System.Threading.Tasks;
using GitHub.Primitives;
using Octokit;
using System;
using GitHub.Authentication.CredentialManagement;
namespace GitHub.Services
{
public class SimpleCredentialStore : ICredentialStore
{
readonly HostAddress hostAddress;
public SimpleCredentialStore(HostAddress hostAddress)
{
this.hostAddress = hostAddress;
}
public Task<Credentials> GetCredentials()
{
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
using (var credential = new Credential())
{
credential.Target = keyHost;
credential.Type = CredentialType.Generic;
if (credential.Load())
return Task.FromResult(new Credentials(credential.Username, credential.Password));
}
return Task.FromResult(Credentials.Anonymous);
}
static string GetKeyHost(string key)
{
key = FormatKey(key);
if (key.StartsWith("git:", StringComparison.Ordinal))
key = key.Substring("git:".Length);
if (!key.EndsWith("/", StringComparison.Ordinal))
key += '/';
return key;
}
static string FormatKey(string key)
{
if (key.StartsWith("login:", StringComparison.Ordinal))
key = key.Substring("login:".Length);
return key;
}
static string GetKeyGit(string key)
{
key = FormatKey(key);
// it appears this is how MS expects the host key
if (!key.StartsWith("git:", StringComparison.Ordinal))
key = "git:" + key;
if (key.EndsWith("/", StringComparison.Ordinal))
key = key.Substring(0, key.Length - 1);
return key;
}
}
}

Просмотреть файл

@ -6,8 +6,8 @@ using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using Akavache;
using GitHub.Authentication.CredentialManagement;
using GitHub.Helpers;
using GitHub.Authentication.CredentialManagement;
namespace GitHub.Caches
{

Просмотреть файл

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<NullGuard ExcludeRegex="^GitHub.Authentication.CredentialManagement.*$"/>
<NullGuard ExcludeRegex="^GitHub.SampleData.*$"/>
</Weavers>

Просмотреть файл

@ -123,12 +123,6 @@
<Compile Include="Services\GitClient.cs" />
<Compile Include="Services\RepositoryCloneService.cs" />
<Compile Include="Extensions\FileExtensions.cs" />
<Compile Include="Authentication\CredentialManagement\Credential.cs" />
<Compile Include="Authentication\CredentialManagement\CredentialSet.cs" />
<Compile Include="Authentication\CredentialManagement\CredentialType.cs" />
<Compile Include="Authentication\CredentialManagement\NativeMethods.cs" />
<Compile Include="Authentication\CredentialManagement\PersistenceType.cs" />
<Compile Include="Authentication\CredentialManagement\SecureStringHelper.cs" />
<Compile Include="Caches\CredentialCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\..\script\SolutionInfo.cs">
@ -225,6 +219,10 @@
<Project>{252ce1c2-027a-4445-a3c2-e4d6c80a935a}</Project>
<Name>Splat-Net45</Name>
</ProjectReference>
<ProjectReference Include="..\CredentialManagement\CredentialManagement.csproj">
<Project>{41a47c5b-c606-45b4-b83c-22b9239e4da0}</Project>
<Name>CredentialManagement</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Exports.Reactive\GitHub.Exports.Reactive.csproj">
<Project>{e4ed0537-d1d9-44b6-9212-3096d7c3f7a1}</Project>
<Name>GitHub.Exports.Reactive</Name>

Просмотреть файл

@ -421,6 +421,10 @@
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;GetCopyToOutputDirectoryItems;DebugSymbolsProjectOutputGroup;</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup;</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>
<ProjectReference Include="..\CredentialManagement\CredentialManagement.csproj">
<Project>{41a47c5b-c606-45b4-b83c-22b9239e4da0}</Project>
<Name>CredentialManagement</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Api\GitHub.Api.csproj">
<Project>{b389adaf-62cc-486e-85b4-2d8b078df763}</Project>
<Name>GitHub.Api</Name>