From b6d0cb77ee8093913fdfc29a982d95d1d800dbf2 Mon Sep 17 00:00:00 2001 From: hsu Date: Wed, 8 Mar 2023 09:41:03 +0800 Subject: [PATCH] Added opc ua server sample --- README.md | 4 +- src/GodSharpOpcDaSample/README.md | 2 +- .../GodSharpOpcUaDiscoveryServer.csproj | 14 +++ src/GodSharpOpcUaDiscoveryServer/Program.cs | 54 +++++++++++ src/GodSharpOpcUaDiscoveryServer/README.md | 65 +++++++++++++ .../GodSharpOpcUaServer.csproj | 14 +++ src/GodSharpOpcUaServer/Program.cs | 63 ++++++++++++ src/GodSharpOpcUaServer/README.md | 97 +++++++++++++++++++ 8 files changed, 311 insertions(+), 2 deletions(-) create mode 100644 src/GodSharpOpcUaDiscoveryServer/GodSharpOpcUaDiscoveryServer.csproj create mode 100644 src/GodSharpOpcUaDiscoveryServer/Program.cs create mode 100644 src/GodSharpOpcUaDiscoveryServer/README.md create mode 100644 src/GodSharpOpcUaServer/GodSharpOpcUaServer.csproj create mode 100644 src/GodSharpOpcUaServer/Program.cs create mode 100644 src/GodSharpOpcUaServer/README.md diff --git a/README.md b/README.md index e8bac16..71956b2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ |Name|NuGet|MyGet| |---|---|---| | GodSharp.Opc.Da | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da) | -| GodSharp.Opc.Da.OpcAutomation | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation) | [![MyGet](https://img.shields.io/myget/godsharplab/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation) | +| GodSharp.Opc.Da.OpcAutomation | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation) | | GodSharp.Opc.Da.OpcAutomation.Kepware | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation.Kepware?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation.Kepware) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation.Kepware?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation.Kepware) | | GodSharp.Opc.Da.OpcAutomation.Graybox | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation.Graybox?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation.Graybox) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation.Graybox?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation.Graybox) | | GodSharp.Opc.Da.OpcNetApi | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcNetApi?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcNetApi) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcNetApi?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcNetApi) | @@ -27,6 +27,8 @@ ### [GodSharp.Opc.Da](./src/GodSharpOpcDaSample/README.md) ### [GodSharp.Opc.Ua.Client](./src/GodSharpOpcUaClientSample/README.md) +### [GodSharp.Opc.Ua.Server](./src/GodSharpOpcUaServer/README.md) +### [GodSharp.Opc.Ua.DiscoveryServer](./src/GodSharpOpcUaDiscoveryServer/README.md) ## Contact diff --git a/src/GodSharpOpcDaSample/README.md b/src/GodSharpOpcDaSample/README.md index 03822ef..45a2888 100644 --- a/src/GodSharpOpcDaSample/README.md +++ b/src/GodSharpOpcDaSample/README.md @@ -8,7 +8,7 @@ |Name|NuGet|MyGet| |---|---|---| | GodSharp.Opc.Da | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da) | -| GodSharp.Opc.Da.OpcAutomation | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation) | [![MyGet](https://img.shields.io/myget/godsharplab/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation) | +| GodSharp.Opc.Da.OpcAutomation | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation) | | GodSharp.Opc.Da.OpcAutomation.Kepware | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation.Kepware?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation.Kepware) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation.Kepware?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation.Kepware) | | GodSharp.Opc.Da.OpcAutomation.Graybox | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcAutomation.Graybox?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcAutomation.Graybox) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcAutomation.Graybox?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcAutomation.Graybox) | | GodSharp.Opc.Da.OpcNetApi | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Da.OpcNetApi?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Da.OpcNetApi) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Da.OpcNetApi?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Da.OpcNetApi) | diff --git a/src/GodSharpOpcUaDiscoveryServer/GodSharpOpcUaDiscoveryServer.csproj b/src/GodSharpOpcUaDiscoveryServer/GodSharpOpcUaDiscoveryServer.csproj new file mode 100644 index 0000000..f3f60d2 --- /dev/null +++ b/src/GodSharpOpcUaDiscoveryServer/GodSharpOpcUaDiscoveryServer.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/src/GodSharpOpcUaDiscoveryServer/Program.cs b/src/GodSharpOpcUaDiscoveryServer/Program.cs new file mode 100644 index 0000000..abe4d95 --- /dev/null +++ b/src/GodSharpOpcUaDiscoveryServer/Program.cs @@ -0,0 +1,54 @@ +// See https://aka.ms/new-console-template for more information +using GodSharp.Opc.Ua; + +using Opc.Ua; + +Console.WriteLine("Hello, GodSharpOpcUaDiscoveryServer!"); +// Auto Generate ApplicationConfigurationFile +// GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; + +// Configuration for UA Discovery Server +ApplicationConfiguration? configuration = null; +configuration = await GodSharp.Opc.Ua.OpcUaHelper.DiscoveryServerConfigurationAsync( + "GodSharpOpcUaDiscoveryServer", + "GodSharp Opc Ua Discovery Server", + new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } + //,(s, e) => CertificateValidationHandler(configuration, s, e) + , CertificateValidationHandler + ); + +// Instance UA Server +var ds = new OpcUaDiscoveryServer(TimeSpan.FromSeconds(15)); + +// Start UA Discovery Server +ds.Start(configuration); +Console.WriteLine("GodSharpOpcUaDiscoveryServer Started!"); +Console.ReadLine(); + +// Start UA Discovery Server +ds.Stop(); + +static void CertificateValidationHandler( + //ApplicationConfiguration configuration, + CertificateValidator sender, CertificateValidationEventArgs e) +{ + if (e.Error.StatusCode.Code == StatusCodes.BadCertificateUntrusted) + { + e.Accept = true; + //return; + //if (!Directory.Exists(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath)) + //{ + // Directory.CreateDirectory(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath); + //} + + //if (configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates) + //{ + // using (var store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore()) + // { + // store.Add(e.Certificate); + // } + // e.Accept = true; + // return; + //} + } +} \ No newline at end of file diff --git a/src/GodSharpOpcUaDiscoveryServer/README.md b/src/GodSharpOpcUaDiscoveryServer/README.md new file mode 100644 index 0000000..8c01eb1 --- /dev/null +++ b/src/GodSharpOpcUaDiscoveryServer/README.md @@ -0,0 +1,65 @@ +# GodSharp.Opc.Ua.DiscoveryServer + +![Azure DevOps builds (main)](https://img.shields.io/azure-devops/build/godsharp/public/4/main?label=azure%20pipelines&style=flat-square) + +## Package Version + +|Name|NuGet|MyGet| +|---|---|---| +| GodSharp.Opc.Ua.Common | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Common?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Common) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Common?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Common) | +| GodSharp.Opc.Ua.Client | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Client?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Client) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Client?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Client) | +| GodSharp.Opc.Ua.ProxyServer | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ProxyServer) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ProxyServer) | +| GodSharp.Opc.Ua.Server | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server) | +| GodSharp.Opc.Ua.Server.AspNetCore | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server.AspNetCore) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server.AspNetCore) | +| GodSharp.Opc.Ua.ComplexTypes | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ComplexTypes) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ComplexTypes) | + +## Introduction + +|Package|Uasge| +|---:|:---| +| GodSharp.Opc.Ua.Common | a opc ua common lib | +| GodSharp.Opc.Ua.Client | a opc ua client | +| GodSharp.Opc.Ua.ProxyServer | a proxy for opc ua server | +| GodSharp.Opc.Ua.Server | a opc ua server | +| GodSharp.Opc.Ua.Server.AspNetCore | opc ua server for asp.net core | +| GodSharp.Opc.Ua.ComplexTypes | custom generate encode/decode method for `EncodeableObject` class | + +## Getting Started + + ```ps + PM> Install-Package GodSharp.Opc.Ua.Common + ``` + +### Configuration + + ```csharp + // Auto Generate ApplicationConfigurationFile + // GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; + + // Configuration for UA Discovery Server + ApplicationConfiguration? configuration = null; + configuration = await GodSharp.Opc.Ua.OpcUaHelper.DiscoveryServerConfigurationAsync( + "GodSharpOpcUaDiscoveryServer", + "GodSharp Opc Ua Discovery Server", + new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } + //,(s, e) => CertificateValidationHandler(configuration, s, e) + , CertificateValidationHandler + ); + ``` + +### Instance + + ```csharp + // Instance UA Discovery Server + var ds = new OpcUaDiscoveryServer(TimeSpan.FromSeconds(15)); + + // Start UA Discovery Server + ds.Start(configuration); + + // Start UA Discovery Server + ds.Stop(); + ``` + +## License + + **Free!** \ No newline at end of file diff --git a/src/GodSharpOpcUaServer/GodSharpOpcUaServer.csproj b/src/GodSharpOpcUaServer/GodSharpOpcUaServer.csproj new file mode 100644 index 0000000..e428fa1 --- /dev/null +++ b/src/GodSharpOpcUaServer/GodSharpOpcUaServer.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/src/GodSharpOpcUaServer/Program.cs b/src/GodSharpOpcUaServer/Program.cs new file mode 100644 index 0000000..942c8d3 --- /dev/null +++ b/src/GodSharpOpcUaServer/Program.cs @@ -0,0 +1,63 @@ +// See https://aka.ms/new-console-template for more information +using GodSharp.Opc.Ua.Server; + +using Opc.Ua; + +Console.WriteLine("Hello, GodSharpOpcUaServer!"); + +// Auto Generate ApplicationConfigurationFile +GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; + +// Configuration for UA Server +ApplicationConfiguration? configuration = null; +configuration = await GodSharp.Opc.Ua.OpcUaHelper.ServerConfigurationAsync( + "GodSharpOpcUaServer", + "GodSharp Opc Ua Server", + new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } + //,(s, e) => CertificateValidationHandler(configuration, s, e) + , CertificateValidationHandler + ); + +// Instance UA Server +var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter()); + +// Start server +server.Start(configuration); + +Console.WriteLine("GodSharpOpcUaServer Started!"); +string? input = null; + +do +{ + input = Console.ReadLine(); + + if (input == null) continue; +} while (input != "q"); + +// Stop server +server.Stop(); + +static void CertificateValidationHandler( + //ApplicationConfiguration configuration, + CertificateValidator sender, CertificateValidationEventArgs e) +{ + if (e.Error.StatusCode.Code == StatusCodes.BadCertificateUntrusted) + { + e.Accept = true; + //return; + //if (!Directory.Exists(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath)) + //{ + // Directory.CreateDirectory(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath); + //} + + //if (configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates) + //{ + // using (var store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore()) + // { + // store.Add(e.Certificate); + // } + // e.Accept = true; + // return; + //} + } +} \ No newline at end of file diff --git a/src/GodSharpOpcUaServer/README.md b/src/GodSharpOpcUaServer/README.md new file mode 100644 index 0000000..dd7aed9 --- /dev/null +++ b/src/GodSharpOpcUaServer/README.md @@ -0,0 +1,97 @@ +# GodSharp.Opc.Ua.Server + +![Azure DevOps builds (main)](https://img.shields.io/azure-devops/build/godsharp/public/4/main?label=azure%20pipelines&style=flat-square) + +## Package Version + +|Name|NuGet|MyGet| +|---|---|---| +| GodSharp.Opc.Ua.Common | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Common?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Common) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Common?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Common) | +| GodSharp.Opc.Ua.Client | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Client?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Client) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Client?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Client) | +| GodSharp.Opc.Ua.ProxyServer | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ProxyServer) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ProxyServer) | +| GodSharp.Opc.Ua.Server | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server) | +| GodSharp.Opc.Ua.Server.AspNetCore | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server.AspNetCore) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server.AspNetCore) | +| GodSharp.Opc.Ua.ComplexTypes | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ComplexTypes) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ComplexTypes) | + +## Introduction + +|Package|Uasge| +|---:|:---| +| GodSharp.Opc.Ua.Common | a opc ua common lib | +| GodSharp.Opc.Ua.Client | a opc ua client | +| GodSharp.Opc.Ua.ProxyServer | a proxy for opc ua server | +| GodSharp.Opc.Ua.Server | a opc ua server | +| GodSharp.Opc.Ua.Server.AspNetCore | opc ua server for asp.net core | +| GodSharp.Opc.Ua.ComplexTypes | custom generate encode/decode method for `EncodeableObject` class | + +## Getting Started + + ```ps + PM> Install-Package GodSharp.Opc.Ua.Server + ``` + +### Configuration + + ```csharp + // Auto Generate ApplicationConfigurationFile + GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; + + // Configuration for UA Server + ApplicationConfiguration? configuration = null; + configuration = await GodSharp.Opc.Ua.OpcUaHelper.ServerConfigurationAsync( + "GodSharpOpcUaServer", + "GodSharp Opc Ua Server", + new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } + //,(s, e) => CertificateValidationHandler(configuration, s, e) + , CertificateValidationHandler + ); + + // Instance UA Server + var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter ()); + + // Start server + server.Start(configuration); + ``` + +### Instance + + ```csharp + // Instance UA Server + var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter ()); + + // Start server + server.Start(configuration); + + // Stop server + server.Stop(); + ``` + +### ServerAuthorizationFilter + + Used to authorized user token. + + ```csharp + public class SampleServerAuthorizationFilter : IServerAuthorizationFilter + { + public ServerAuthorizationResult Verify(UserNameIdentityToken token) + { + string userName = token.UserName; + string decryptedPassword = token.DecryptedPassword; + if (userName == "admin" && decryptedPassword == "admin@password") + { + return new ServerAuthorizationResult(Authorized: true, Administrator: true); + } + + if (userName == "user" && decryptedPassword == "user@password") + { + return new ServerAuthorizationResult(Authorized: true); + } + + return new ServerAuthorizationResult(Authorized: false); + } + } + ``` + +## License + + **Free!** \ No newline at end of file