-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for Typeform provider
- Loading branch information
Showing
16 changed files
with
967 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Owin.Security.Providers.Typeform | ||
{ | ||
public static class Constants | ||
{ | ||
public const string DefaultAuthenticationType = "Typeform"; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/Owin.Security.Providers.Typeform/Owin.Security.Providers.Typeform.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?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>{C8862B45-E1D1-4AB7-A83D-3A2FD2A22526}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Owin.Security.Providers.Typeform</RootNamespace> | ||
<AssemblyName>Owin.Security.Providers.Typeform</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</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>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<LangVersion>6</LangVersion> | ||
</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> | ||
<LangVersion>6</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.Owin.Security, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Net.Http.WebRequest" /> | ||
<Reference Include="System.Web" /> | ||
<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> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Constants.cs" /> | ||
<Compile Include="Resources.Designer.cs"> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
</Compile> | ||
<Compile Include="TypeformAuthenticationExtensions.cs" /> | ||
<Compile Include="TypeformAuthenticationHandler.cs" /> | ||
<Compile Include="TypeformAuthenticationMiddleware.cs" /> | ||
<Compile Include="TypeformAuthenticationOptions.cs" /> | ||
<Compile Include="Provider\ITypeformAuthenticationProvider.cs" /> | ||
<Compile Include="Provider\TypeformAuthenticatedContext.cs" /> | ||
<Compile Include="Provider\TypeformAuthenticationProvider.cs" /> | ||
<Compile Include="Provider\TypeformReturnEndpointContext.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="C:\projects\GitHub\OwinOAuthProviders\Owin.Security.Providers.Typeform\Owin.Security.Providers.Typeform.nuspec" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="PostBuildMacros"> | ||
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)"> | ||
<Output TaskParameter="Assemblies" ItemName="Targets" /> | ||
</GetAssemblyIdentity> | ||
<ItemGroup> | ||
<VersionNumber Include="@(Targets->'%(Version)')" /> | ||
</ItemGroup> | ||
</Target> | ||
<PropertyGroup> | ||
<PreBuildEvent> | ||
</PreBuildEvent> | ||
<PostBuildEventDependsOn> | ||
$(PostBuildEventDependsOn); | ||
PostBuildMacros; | ||
</PostBuildEventDependsOn> | ||
</PropertyGroup> | ||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/Owin.Security.Providers.Typeform/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("Owin.Security.Providers.Typeform")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Owin.Security.Providers.Typeform")] | ||
[assembly: AssemblyCopyright("Copyright © 2016")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: Guid("b6a4a4cb-d365-41a0-b4c9-966e7ef19de0")] | ||
[assembly: AssemblyVersion("2.0.0.0")] | ||
[assembly: AssemblyFileVersion("2.0.0.0")] |
24 changes: 24 additions & 0 deletions
24
src/Owin.Security.Providers.Typeform/Provider/ITypeformAuthenticationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Owin.Security.Providers.Typeform | ||
{ | ||
/// <summary> | ||
/// Specifies callback methods which the <see cref="TypeformAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. /> | ||
/// </summary> | ||
public interface ITypeformAuthenticationProvider | ||
{ | ||
/// <summary> | ||
/// Invoked whenever Typeform successfully authenticates a user | ||
/// </summary> | ||
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param> | ||
/// <returns>A <see cref="Task"/> representing the completed operation.</returns> | ||
Task Authenticated(TypeformAuthenticatedContext context); | ||
|
||
/// <summary> | ||
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns>A <see cref="Task"/> representing the completed operation.</returns> | ||
Task ReturnEndpoint(TypeformReturnEndpointContext context); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/Owin.Security.Providers.Typeform/Provider/TypeformAuthenticatedContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security; | ||
using Microsoft.Owin.Security.Provider; | ||
|
||
namespace Owin.Security.Providers.Typeform | ||
{ | ||
/// <summary> | ||
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>. | ||
/// </summary> | ||
public class TypeformAuthenticatedContext : BaseContext | ||
{ | ||
/// <summary> | ||
/// Initializes a <see cref="TypeformAuthenticatedContext"/> | ||
/// </summary> | ||
/// <param name="context">The OWIN environment</param> | ||
/// <param name="userJson">The JSON-serialized user</param> | ||
/// <param name="accessToken">Typeform Access token</param> | ||
/// <param name="refreshToken">Typeform Refresh token</param> | ||
/// <param name="instanceUrl">Typeform instance url</param> | ||
public TypeformAuthenticatedContext(IOwinContext context, string accessToken) | ||
: base(context) | ||
{ | ||
AccessToken = accessToken; | ||
|
||
// Typeform doesn't supply a unique identifier for the user, | ||
// however according to https://developer.typeform.com/get-started/applications/ | ||
// the access token doesn't expire so we can use it as a proxy for UserId | ||
UserId = ComputeHash(accessToken); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Typeform access token | ||
/// </summary> | ||
public string AccessToken { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the Typeform User ID | ||
/// </summary> | ||
public string UserId { get; private set; } | ||
|
||
|
||
/// <summary> | ||
/// Gets the <see cref="ClaimsIdentity"/> representing the user | ||
/// </summary> | ||
public ClaimsIdentity Identity { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a property bag for common authentication properties | ||
/// </summary> | ||
public AuthenticationProperties Properties { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
private static string ComputeHash(string input) | ||
{ | ||
if (String.IsNullOrEmpty(input)) return null; | ||
|
||
byte[] bytes; | ||
using (var hash = System.Security.Cryptography.SHA1.Create()) { | ||
bytes = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)); | ||
} | ||
|
||
return String.Concat(bytes.Select(x => x.ToString("x2"))); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Owin.Security.Providers.Typeform/Provider/TypeformAuthenticationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Owin.Security.Providers.Typeform | ||
{ | ||
/// <summary> | ||
/// Default <see cref="ITypeformAuthenticationProvider"/> implementation. | ||
/// </summary> | ||
public class TypeformAuthenticationProvider : ITypeformAuthenticationProvider | ||
{ | ||
/// <summary> | ||
/// Initializes a <see cref="TypeformAuthenticationProvider"/> | ||
/// </summary> | ||
public TypeformAuthenticationProvider() | ||
{ | ||
OnAuthenticated = context => Task.FromResult<object>(null); | ||
OnReturnEndpoint = context => Task.FromResult<object>(null); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the function that is invoked when the Authenticated method is invoked. | ||
/// </summary> | ||
public Func<TypeformAuthenticatedContext, Task> OnAuthenticated { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked. | ||
/// </summary> | ||
public Func<TypeformReturnEndpointContext, Task> OnReturnEndpoint { get; set; } | ||
|
||
/// <summary> | ||
/// Invoked whenever Typeform successfully authenticates a user | ||
/// </summary> | ||
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param> | ||
/// <returns>A <see cref="Task"/> representing the completed operation.</returns> | ||
public virtual Task Authenticated(TypeformAuthenticatedContext context) | ||
{ | ||
return OnAuthenticated(context); | ||
} | ||
|
||
/// <summary> | ||
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns>A <see cref="Task"/> representing the completed operation.</returns> | ||
public virtual Task ReturnEndpoint(TypeformReturnEndpointContext context) | ||
{ | ||
return OnReturnEndpoint(context); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Owin.Security.Providers.Typeform/Provider/TypeformReturnEndpointContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security; | ||
using Microsoft.Owin.Security.Provider; | ||
|
||
namespace Owin.Security.Providers.Typeform | ||
{ | ||
/// <summary> | ||
/// Provides context information to middleware providers. | ||
/// </summary> | ||
public class TypeformReturnEndpointContext : ReturnEndpointContext | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="context">OWIN environment</param> | ||
/// <param name="ticket">The authentication ticket</param> | ||
public TypeformReturnEndpointContext( | ||
IOwinContext context, | ||
AuthenticationTicket ticket) | ||
: base(context, ticket) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.