-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from Code-Sharp/wampv2-authentication-welcome-…
…merge WAMPv2 client authentication features
- Loading branch information
Showing
18 changed files
with
655 additions
and
182 deletions.
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
6 changes: 6 additions & 0 deletions
6
src/net45/Samples/WAMP2/WampSharp.Samples.Authentication/App.config
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
122 changes: 122 additions & 0 deletions
122
src/net45/Samples/WAMP2/WampSharp.Samples.Authentication/Program.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,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WampSharp.Binding; | ||
using WampSharp.V2; | ||
using WampSharp.V2.Client; | ||
using WampSharp.V2.Rpc; | ||
|
||
namespace WampSharp.Samples.Authentication | ||
{ | ||
public interface IArgumentsService | ||
{ | ||
[WampProcedure("com.timeservice.now")] | ||
string timeservice(); | ||
} | ||
|
||
public class CustomAuthenticator : IWampClientAutenticator | ||
{ | ||
private string[] authenticationMethods; | ||
private IDictionary<string, string> tickets = new Dictionary<string, string>() | ||
{ | ||
{ "peter", "md5f39d45e1da71cf755a7ee5d5840c7b0d" }, | ||
{ "joe", "magic_secret_2" } | ||
}; | ||
private string user = "peter"; | ||
|
||
public CustomAuthenticator() | ||
{ | ||
this.authenticationMethods = new string[] { "ticket" }; | ||
} | ||
|
||
public ChallengeResult Authenticate(string challenge, ChallengeDetails extra) | ||
{ | ||
var challengeExtra = extra.OriginalValue.Deserialize<IDictionary<string, object>>(); | ||
|
||
var method = (string)challengeExtra["authmethod"]; | ||
Console.WriteLine(method); | ||
foreach (var ce in challengeExtra) | ||
{ | ||
Console.WriteLine(ce); | ||
} | ||
|
||
if (method == "ticket") | ||
{ | ||
Console.WriteLine("authenticating via '" + method + "'"); | ||
var result = new ChallengeResult(); | ||
result.Signature = tickets[user]; | ||
result.Extra = new Dictionary<string, object>() { }; | ||
return result; | ||
} | ||
else | ||
{ | ||
throw new WampAuthenticationException("don't know how to authenticate using '" + method + "'"); | ||
} | ||
} | ||
|
||
public string[] AuthenticationMethods | ||
{ | ||
get { return authenticationMethods; } | ||
} | ||
|
||
public string AuthenticationId | ||
{ | ||
get { return user; } | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
private static IWampRealmProxy proxy; | ||
|
||
private static void Test(IWampRealmServiceProvider serviceProvider) | ||
{ | ||
IArgumentsService proxy = serviceProvider.GetCalleeProxy<IArgumentsService>(); | ||
string now; | ||
try | ||
{ | ||
now = proxy.timeservice(); | ||
Console.WriteLine("call result {0}", now); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine("call error {0}", e); | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
string url = "ws://127.0.0.1:8080/"; | ||
string realm = "integra-s"; | ||
|
||
DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); | ||
|
||
IWampClientAutenticator authenticator = new CustomAuthenticator(); | ||
IWampChannel channel = channelFactory.CreateJsonChannel(url, realm, authenticator); | ||
channel.RealmProxy.Monitor.ConnectionEstablished += Monitor_ConnectionEstablished; | ||
channel.RealmProxy.Monitor.ConnectionBroken += Monitor_ConnectionBroken; | ||
Program.proxy = channel.RealmProxy; | ||
channel.Open().Wait(); | ||
Test(channel.RealmProxy.Services); | ||
Console.ReadLine(); | ||
} | ||
|
||
static void Monitor_ConnectionEstablished(object sender, V2.Realm.WampSessionEventArgs e) | ||
{ | ||
var details = e.Details.Deserialize<IDictionary<string, object>>(); | ||
|
||
Console.WriteLine("connected session with ID " + e.SessionId); | ||
Console.WriteLine("authenticated using method '" + details["authmethod"] + "' and provider '" + details["authprovider"] + "'"); | ||
Console.WriteLine("authenticated with authid '" + details["authid"] + "' and authrole '" + details["authrole"] + "'"); | ||
|
||
//Test(Program.proxy.Services); | ||
} | ||
|
||
static void Monitor_ConnectionBroken(object sender, V2.Realm.WampSessionCloseEventArgs e) | ||
{ | ||
Console.WriteLine("disconnected {0}", e.Reason); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/net45/Samples/WAMP2/WampSharp.Samples.Authentication/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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("WampSharp.Samples.Authentication")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("WampSharp.Samples.Authentication")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("3e3df86c-9d5d-45f5-858d-5e653c196d58")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
68 changes: 68 additions & 0 deletions
68
...45/Samples/WAMP2/WampSharp.Samples.Authentication/WampSharp.Samples.Authentication.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,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.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>{305C0F3D-1A51-4D8C-8729-481F73A7C7D6}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>WampSharp.Samples.Authentication</RootNamespace> | ||
<AssemblyName>WampSharp.Samples.Authentication</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<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' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<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.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\WampSharp.Default\WampSharp.Default.csproj"> | ||
<Project>{6ab75291-d296-457e-88a3-b41b16a1a247}</Project> | ||
<Name>WampSharp.Default</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\..\..\WampSharp\WampSharp.csproj"> | ||
<Project>{653a76dc-00d7-4eff-a25e-2fa10c5c927d}</Project> | ||
<Name>WampSharp</Name> | ||
</ProjectReference> | ||
</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> |
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
Oops, something went wrong.