Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.ObjectModel;
using DotNetOpenAuth.AspNet;
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// A collection to store instances of IAuthenticationClient by keying off ProviderName.
/// </summary>
internal sealed class AuthenticationClientCollection : KeyedCollection<string, IAuthenticationClient>
{
public AuthenticationClientCollection()
: base(StringComparer.OrdinalIgnoreCase)
{
}
protected override string GetKeyForItem(IAuthenticationClient item)
{
return item.ProviderName;
}
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// Represents built in OAuth clients.
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "OAuth", Justification = "OAuth is a brand name.")]
public enum BuiltInOAuthClient
{
/// <summary>
/// Represents Twitter OAuth client
/// </summary>
Twitter,
/// <summary>
/// Represents Facebook OAuth client
/// </summary>
Facebook,
/// <summary>
/// Represents LinkedIn OAuth client
/// </summary>
LinkedIn,
/// <summary>
/// Represents WindowsLive OAuth client
/// </summary>
WindowsLive
}
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// Represents built in OpenID clients.
/// </summary>
public enum BuiltInOpenIDClient
{
/// <summary>
/// Represents Google OpenID client
/// </summary>
Google,
/// <summary>
/// Represents Yahoo OpenID Client
/// </summary>
Yahoo
}
}

View File

@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4CBFC7D3-1600-4CE5-BC6B-AC7BC2D6F853}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Web.WebPages.OAuth</RootNamespace>
<AssemblyName>Microsoft.Web.WebPages.OAuth</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;ASPNETWEBPAGES</DefineConstants>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>..\..\bin\Debug\Microsoft.Web.WebPages.OAuth.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE;ASPNETWEBPAGES</DefineConstants>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'CodeCoverage|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\CodeCoverage\</OutputPath>
<DefineConstants>TRACE;DEBUG;CODE_COVERAGE;ASPNETWEBPAGES</DefineConstants>
<DebugType>full</DebugType>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CodeAnalysisDictionary.xml" />
</ItemGroup>
<ItemGroup>
<Reference Include="DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.AspNet.4.0.0.12084\lib\net40-full\DotNetOpenAuth.AspNet.dll</HintPath>
</Reference>
<Reference Include="DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.Core.4.0.0.12084\lib\net40-full\DotNetOpenAuth.Core.dll</HintPath>
</Reference>
<Reference Include="DotNetOpenAuth.OAuth, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.OAuth.Core.4.0.0.12084\lib\net40-full\DotNetOpenAuth.OAuth.dll</HintPath>
</Reference>
<Reference Include="DotNetOpenAuth.OAuth.Consumer, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.OAuth.Consumer.4.0.0.12084\lib\net40-full\DotNetOpenAuth.OAuth.Consumer.dll</HintPath>
</Reference>
<Reference Include="DotNetOpenAuth.OpenId, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.OpenId.Core.4.0.0.12084\lib\net40-full\DotNetOpenAuth.OpenId.dll</HintPath>
</Reference>
<Reference Include="DotNetOpenAuth.OpenId.RelyingParty, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetOpenAuth.OpenId.RelyingParty.4.0.0.12084\lib\net40-full\DotNetOpenAuth.OpenId.RelyingParty.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\GlobalSuppressions.cs">
<Link>Common\GlobalSuppressions.cs</Link>
</Compile>
<Compile Include="AuthenticationClientCollection.cs" />
<Compile Include="BuiltInOAuthClient.cs" />
<Compile Include="BuiltInOpenIDClient.cs" />
<Compile Include="OAuthAccount.cs" />
<Compile Include="OAuthWebSecurity.cs" />
<Compile Include="PreApplicationStartCode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\WebResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>WebResources.resx</DependentUpon>
</Compile>
<Compile Include="WebPagesOAuthDataProvider.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Web.Razor\System.Web.Razor.csproj">
<Project>{8F18041B-9410-4C36-A9C5-067813DF5F31}</Project>
<Name>System.Web.Razor</Name>
</ProjectReference>
<ProjectReference Include="..\System.Web.WebPages.Razor\System.Web.WebPages.Razor.csproj">
<Project>{0939B11A-FE4E-4BA1-8AD6-D97741EE314F}</Project>
<Name>System.Web.WebPages.Razor</Name>
</ProjectReference>
<ProjectReference Include="..\WebMatrix.WebData\WebMatrix.WebData.csproj">
<Project>{55A15F40-1435-4248-A7F2-2A146BB83586}</Project>
<Name>WebMatrix.WebData</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\WebResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>WebResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

View File

@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Globalization;
using Microsoft.Web.WebPages.OAuth.Properties;
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// Represents an OAuth &amp; OpenID account.
/// </summary>
public class OAuthAccount
{
/// <summary>
/// Initializes a new instance of the <see cref="OAuthAccount"/> class.
/// </summary>
/// <param name="provider">The provider.</param>
/// <param name="providerUserId">The provider user id.</param>
public OAuthAccount(string provider, string providerUserId)
{
if (String.IsNullOrEmpty(provider))
{
throw new ArgumentException(
String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "provider"),
"provider");
}
if (string.IsNullOrEmpty(providerUserId))
{
throw new ArgumentException(
String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "providerUserId"),
"providerUserId");
}
Provider = provider;
ProviderUserId = providerUserId;
}
/// <summary>
/// Gets the provider name.
/// </summary>
public string Provider { get; private set; }
/// <summary>
/// Gets the provider user id.
/// </summary>
public string ProviderUserId { get; private set; }
}
}

View File

@@ -0,0 +1,324 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Security;
using DotNetOpenAuth.AspNet;
using DotNetOpenAuth.AspNet.Clients;
using Microsoft.Web.WebPages.OAuth.Properties;
using WebMatrix.WebData;
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// Contains APIs to manage authentication against OAuth &amp; OpenID service providers
/// </summary>
public static class OAuthWebSecurity
{
internal static IOpenAuthDataProvider OAuthDataProvider = new WebPagesOAuthDataProvider();
// contains all registered authentication clients
private static readonly AuthenticationClientCollection _authenticationClients = new AuthenticationClientCollection();
/// <summary>
/// Gets a value indicating whether the current user is authenticated by an OAuth provider.
/// </summary>
public static bool IsAuthenticatedWithOAuth
{
get
{
if (HttpContext.Current == null)
{
throw new InvalidOperationException(WebResources.HttpContextNotAvailable);
}
return GetIsAuthenticatedWithOAuthCore(new HttpContextWrapper(HttpContext.Current));
}
}
/// <summary>
/// Registers a supported OAuth client with the specified consumer key and consumer secret.
/// </summary>
/// <param name="client">One of the supported OAuth clients.</param>
/// <param name="consumerKey">The consumer key.</param>
/// <param name="consumerSecret">The consumer secret.</param>
public static void RegisterOAuthClient(BuiltInOAuthClient client, string consumerKey, string consumerSecret)
{
IAuthenticationClient authenticationClient;
switch (client)
{
case BuiltInOAuthClient.LinkedIn:
authenticationClient = new LinkedInClient(consumerKey, consumerSecret);
break;
case BuiltInOAuthClient.Twitter:
authenticationClient = new TwitterClient(consumerKey, consumerSecret);
break;
case BuiltInOAuthClient.Facebook:
authenticationClient = new FacebookClient(consumerKey, consumerSecret);
break;
case BuiltInOAuthClient.WindowsLive:
authenticationClient = new WindowsLiveClient(consumerKey, consumerSecret);
break;
default:
throw new ArgumentOutOfRangeException("client");
}
RegisterClient(authenticationClient);
}
/// <summary>
/// Registers a supported OpenID client
/// </summary>
public static void RegisterOpenIDClient(BuiltInOpenIDClient openIDClient)
{
IAuthenticationClient client;
switch (openIDClient)
{
case BuiltInOpenIDClient.Google:
client = new GoogleOpenIdClient();
break;
case BuiltInOpenIDClient.Yahoo:
client = new YahooOpenIdClient();
break;
default:
throw new ArgumentOutOfRangeException("openIDClient");
}
RegisterClient(client);
}
/// <summary>
/// Registers an authentication client.
/// </summary>
[CLSCompliant(false)]
public static void RegisterClient(IAuthenticationClient client)
{
if (client == null)
{
throw new ArgumentNullException("client");
}
if (String.IsNullOrEmpty(client.ProviderName))
{
throw new ArgumentException(WebResources.InvalidServiceProviderName, "client");
}
if (_authenticationClients.Contains(client))
{
throw new ArgumentException(WebResources.ServiceProviderNameExists, "client");
}
_authenticationClients.Add(client);
}
/// <summary>
/// Requests the specified provider to start the authentication by directing users to an external website
/// </summary>
/// <param name="provider">The provider.</param>
public static void RequestAuthentication(string provider)
{
RequestAuthentication(provider, returnUrl: null);
}
/// <summary>
/// Requests the specified provider to start the authentication by directing users to an external website
/// </summary>
/// <param name="provider">The provider.</param>
/// <param name="returnUrl">The return url after user is authenticated.</param>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to allow relative app path, and support ~/")]
public static void RequestAuthentication(string provider, string returnUrl)
{
if (HttpContext.Current == null)
{
throw new InvalidOperationException(WebResources.HttpContextNotAvailable);
}
RequestAuthenticationCore(new HttpContextWrapper(HttpContext.Current), provider, returnUrl);
}
internal static void RequestAuthenticationCore(HttpContextBase context, string provider, string returnUrl)
{
IAuthenticationClient client = GetOAuthClient(provider);
var securityManager = new OpenAuthSecurityManager(context, client, OAuthDataProvider);
securityManager.RequestAuthentication(returnUrl);
}
/// <summary>
/// Checks if user is successfully authenticated when user is redirected back to this user.
/// </summary>
[CLSCompliant(false)]
public static AuthenticationResult VerifyAuthentication()
{
if (HttpContext.Current == null)
{
throw new InvalidOperationException(WebResources.HttpContextNotAvailable);
}
return VerifyAuthenticationCore(new HttpContextWrapper(HttpContext.Current));
}
internal static AuthenticationResult VerifyAuthenticationCore(HttpContextBase context)
{
string providerName = OpenAuthSecurityManager.GetProviderName(context);
if (String.IsNullOrEmpty(providerName))
{
return AuthenticationResult.Failed;
}
IAuthenticationClient client;
if (TryGetOAuthClient(providerName, out client))
{
var securityManager = new OpenAuthSecurityManager(context, client, OAuthDataProvider);
return securityManager.VerifyAuthentication();
}
else
{
throw new InvalidOperationException(WebResources.InvalidServiceProviderName);
}
}
/// <summary>
/// Checks if the specified provider user id represents a valid account.
/// If it does, log user in.
/// </summary>
/// <param name="providerName">Name of the provider.</param>
/// <param name="providerUserId">The provider user id.</param>
/// <param name="createPersistentCookie">if set to <c>true</c> create persistent cookie as part of the login.</param>
/// <returns>
/// <c>true</c> if the login is successful.
/// </returns>
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login", Justification = "Login is used more consistently in ASP.Net")]
public static bool Login(string providerName, string providerUserId, bool createPersistentCookie)
{
if (HttpContext.Current == null)
{
throw new InvalidOperationException(WebResources.HttpContextNotAvailable);
}
return LoginCore(new HttpContextWrapper(HttpContext.Current), providerName, providerUserId, createPersistentCookie);
}
internal static bool LoginCore(HttpContextBase context, string providerName, string providerUserId, bool createPersistentCookie)
{
var provider = GetOAuthClient(providerName);
var securityManager = new OpenAuthSecurityManager(context, provider, OAuthDataProvider);
return securityManager.Login(providerUserId, createPersistentCookie);
}
internal static bool GetIsAuthenticatedWithOAuthCore(HttpContextBase context)
{
return new OpenAuthSecurityManager(context).IsAuthenticatedWithOpenAuth;
}
/// <summary>
/// Creates or update the account with the specified provider, provider user id and associate it with the specified user name.
/// </summary>
/// <param name="providerName">Name of the provider.</param>
/// <param name="providerUserId">The provider user id.</param>
/// <param name="userName">The user name.</param>
public static void CreateOrUpdateAccount(string providerName, string providerUserId, string userName)
{
ExtendedMembershipProvider provider = VerifyProvider();
provider.CreateOrUpdateOAuthAccount(providerName, providerUserId, userName);
}
/// <summary>
/// Gets the registered user name corresponding to the specified provider and provider user id.
/// </summary>
/// <param name="providerName">Name of the provider.</param>
/// <param name="providerUserId">The provider user id.</param>
/// <returns></returns>
public static string GetUserName(string providerName, string providerUserId)
{
return OAuthDataProvider.GetUserNameFromOpenAuth(providerName, providerUserId);
}
/// <summary>
/// Gets all OAuth &amp; OpenID accounts which are associted with the specified user name.
/// </summary>
/// <param name="userName">The user name.</param>
public static ICollection<OAuthAccount> GetAccountsFromUserName(string userName)
{
if (String.IsNullOrEmpty(userName))
{
throw new ArgumentException(
String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "userName"),
"userName");
}
ExtendedMembershipProvider provider = VerifyProvider();
return provider.GetAccountsForUser(userName).Select(p => new OAuthAccount(p.Provider, p.ProviderUserId)).ToList();
}
/// <summary>
/// Delete the specified OAuth &amp; OpenID account
/// </summary>
/// <param name="providerName">Name of the provider.</param>
/// <param name="providerUserId">The provider user id.</param>
public static bool DeleteAccount(string providerName, string providerUserId)
{
ExtendedMembershipProvider provider = VerifyProvider();
string username = GetUserName(providerName, providerUserId);
if (String.IsNullOrEmpty(username))
{
// account doesn't exist
return false;
}
provider.DeleteOAuthAccount(providerName, providerName);
return true;
}
internal static IAuthenticationClient GetOAuthClient(string providerName)
{
if (!_authenticationClients.Contains(providerName))
{
throw new ArgumentException(WebResources.ServiceProviderNotFound, "providerName");
}
return _authenticationClients[providerName];
}
internal static bool TryGetOAuthClient(string provider, out IAuthenticationClient client)
{
if (_authenticationClients.Contains(provider))
{
client = _authenticationClients[provider];
return true;
}
else
{
client = null;
return false;
}
}
/// <summary>
/// for unit tests
/// </summary>
internal static void ClearProviders()
{
_authenticationClients.Clear();
}
private static ExtendedMembershipProvider VerifyProvider()
{
var provider = Membership.Provider as ExtendedMembershipProvider;
if (provider == null)
{
throw new InvalidOperationException();
}
return provider;
}
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.ComponentModel;
using System.Web.WebPages.Razor;
namespace Microsoft.Web.WebPages.OAuth
{
/// <summary>
/// Defines Start() method that gets executed when this assembly is loaded by ASP.NET
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class PreApplicationStartCode
{
/// <summary>
/// Register global namepace imports for this assembly
/// </summary>
public static void Start()
{
WebPageRazorHost.AddGlobalImport("DotNetOpenAuth.AspNet");
WebPageRazorHost.AddGlobalImport("Microsoft.Web.WebPages.OAuth");
// Disable the "calls home" feature of DNOA
DotNetOpenAuth.Reporting.Enabled = false;
}
}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Web;
[assembly: AssemblyTitle("Microsoft.Web.WebPages.OAuth")]
[assembly: AssemblyDescription("")]
[assembly: InternalsVisibleTo("Microsoft.Web.WebPages.OAuth.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: PreApplicationStartMethod(typeof(Microsoft.Web.WebPages.OAuth.PreApplicationStartCode), "Start")]

View File

@@ -0,0 +1,108 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.488
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.Web.WebPages.OAuth.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class WebResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal WebResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Web.WebPages.OAuth.Properties.WebResources", typeof(WebResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to {0} cannot be null or an empty string..
/// </summary>
internal static string Argument_Cannot_Be_Null_Or_Empty {
get {
return ResourceManager.GetString("Argument_Cannot_Be_Null_Or_Empty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to HttpContext is not available in the current thread..
/// </summary>
internal static string HttpContextNotAvailable {
get {
return ResourceManager.GetString("HttpContextNotAvailable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid provider name..
/// </summary>
internal static string InvalidServiceProviderName {
get {
return ResourceManager.GetString("InvalidServiceProviderName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Another service provider with the same name has already been registered..
/// </summary>
internal static string ServiceProviderNameExists {
get {
return ResourceManager.GetString("ServiceProviderNameExists", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A service provider could not be found by the specified name..
/// </summary>
internal static string ServiceProviderNotFound {
get {
return ResourceManager.GetString("ServiceProviderNotFound", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Argument_Cannot_Be_Null_Or_Empty" xml:space="preserve">
<value>{0} cannot be null or an empty string.</value>
</data>
<data name="HttpContextNotAvailable" xml:space="preserve">
<value>HttpContext is not available in the current thread.</value>
</data>
<data name="InvalidServiceProviderName" xml:space="preserve">
<value>Invalid provider name.</value>
</data>
<data name="ServiceProviderNameExists" xml:space="preserve">
<value>Another service provider with the same name has already been registered.</value>
</data>
<data name="ServiceProviderNotFound" xml:space="preserve">
<value>A service provider could not be found by the specified name.</value>
</data>
</root>

View File

@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Web.Security;
using DotNetOpenAuth.AspNet;
using WebMatrix.WebData;
namespace Microsoft.Web.WebPages.OAuth
{
internal class WebPagesOAuthDataProvider : IOpenAuthDataProvider
{
private static ExtendedMembershipProvider VerifyProvider()
{
var provider = Membership.Provider as ExtendedMembershipProvider;
if (provider == null)
{
throw new InvalidOperationException();
}
return provider;
}
public string GetUserNameFromOpenAuth(string openAuthProvider, string openAuthId)
{
ExtendedMembershipProvider provider = VerifyProvider();
int userId = provider.GetUserIdFromOAuth(openAuthProvider, openAuthId);
if (userId == -1)
{
return null;
}
return provider.GetUserNameFromId(userId);
}
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetOpenAuth.AspNet" version="4.0.0.12084" />
<package id="DotNetOpenAuth.Core" version="4.0.0.12084" />
<package id="DotNetOpenAuth.OAuth.Consumer" version="4.0.0.12084" />
<package id="DotNetOpenAuth.OAuth.Core" version="4.0.0.12084" />
<package id="DotNetOpenAuth.OpenId.Core" version="4.0.0.12084" />
<package id="DotNetOpenAuth.OpenId.RelyingParty" version="4.0.0.12084" />
</packages>