Skip to content

Commit

Permalink
added JWT decoder tools (#36)
Browse files Browse the repository at this point in the history
* added JWT decoder tools and missing traduction for ru

* updated third party notices

* updated following comment

* Added support of Reflection for System.IdentityModel.Tokens.Jwt in .Net Native

* updated icon

Co-authored-by: Etienne BAUDOUX <ebaudoux@outlook.com>
  • Loading branch information
btiteux and veler committed Oct 15, 2021
1 parent 265ae3b commit 06f3898
Show file tree
Hide file tree
Showing 16 changed files with 877 additions and 3 deletions.
25 changes: 25 additions & 0 deletions THIRD-PARTY-NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project incorporates components from the projects listed below. The origina
9. Monaco Editor (https://github.com/Microsoft/monaco-editor)
10. Monaco Editor UWP (https://github.com/hawkerm/monaco-editor-uwp)
11. Observable Vector (https://github.com/jamesqo/observable-vector)
12. Azure Active Directory IdentityModel Extensions for .NET (https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet)

Newtonsoft.Json NOTICES AND INFORMATION BEGIN HERE
=========================================
Expand Down Expand Up @@ -183,6 +184,30 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Azure Active Directory IdentityModel Extensions for .NET
=========================================
The MIT License (MIT)

Copyright (c) Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
<NuGet_SystemComposition>5.0.0</NuGet_SystemComposition>
<NuGet_Win2D>1.26.0</NuGet_Win2D>
<NuGet_YamlDotNet>11.2.1</NuGet_YamlDotNet>
<NuGet_IdentityModelTokenJwt>6.13.1</NuGet_IdentityModelTokenJwt>
</PropertyGroup>
</Project>
11 changes: 11 additions & 0 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<Compile Include="Core\Threading\ThreadPriority.cs" />
<Compile Include="Core\TitleBar.cs" />
<Compile Include="Core\ToolProviderFactory.cs" />
<Compile Include="Helpers\JwtHelper.cs" />
<Compile Include="Models\IndentationDisplayPair.cs" />
<Compile Include="Models\Indentation.cs" />
<Compile Include="UI\Controls\CodeEditor.xaml.cs">
Expand All @@ -206,6 +207,8 @@
<Compile Include="Helpers\YamlHelper.cs" />
<Compile Include="ViewModels\Tools\JsonYaml\JsonYamlToolProvider.cs" />
<Compile Include="ViewModels\Tools\JsonYaml\JsonYamlToolViewModel.cs" />
<Compile Include="ViewModels\Tools\JwtDecoderEncoder\JwtDecoderEncoderToolProvider.cs" />
<Compile Include="ViewModels\Tools\JwtDecoderEncoder\JwtDecoderEncoderToolViewModel.cs" />
<Compile Include="ViewModels\Tools\ToolProviderBase.cs" />
<Compile Include="Core\UriActivationProtocolService.cs" />
<Compile Include="LanguageDefinition.cs" />
Expand Down Expand Up @@ -274,6 +277,9 @@
<Compile Include="Views\Tools\JsonFormatter\JsonFormatterToolPage.xaml.cs">
<DependentUpon>JsonFormatterToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\JwtDecoderEncoder\JwtDecoderEncoderToolPage.xaml.cs">
<DependentUpon>JwtDecoderEncoderToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\RegEx\RegExToolPage.xaml.cs">
<DependentUpon>RegExToolPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -362,6 +368,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Tools\JwtDecoderEncoder\JwtDecoderEncoderToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Tools\RegEx\RegExToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -389,6 +399,7 @@
<PackageReference Include="Microsoft.UI.Xaml" Version="$(NuGet_MicrosoftUIXaml)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NuGet_NewtonsoftJson)" />
<PackageReference Include="System.Composition" Version="$(NuGet_SystemComposition)" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="$(NuGet_IdentityModelTokenJwt)" />
<PackageReference Include="YamlDotNet" Version="$(NuGet_YamlDotNet)" />
<PackageReference Include="Win2D.uwp" Version="$(Nuget_Win2D)" />
</ItemGroup>
Expand Down
34 changes: 34 additions & 0 deletions src/dev/impl/DevToys/Helpers/JwtHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#nullable enable

using System;
using System.IdentityModel.Tokens.Jwt;

namespace DevToys.Helpers
{
internal static class JwtHelper
{
/// <summary>
/// Detects whether the given string is a JWT Token or not.
/// </summary>
internal static bool IsValid(string? input)
{
if (string.IsNullOrWhiteSpace(input))
{
return false;
}

input = input!.Trim();

try
{
JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
JwtSecurityToken jwtSecurityToken = handler.ReadJwtToken(input);
return jwtSecurityToken is not null;
}
catch (Exception) //some other exception
{
return false;
}
}
}
}
71 changes: 71 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class LanguageManager : ObservableObject
private readonly HashGeneratorStrings _hashgenerator = new HashGeneratorStrings();
private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();
private readonly JsonYamlStrings _jsonyaml = new JsonYamlStrings();
private readonly JwtDecoderEncoderStrings _jwtdecoderencoder = new JwtDecoderEncoderStrings();
private readonly MainPageStrings _mainpage = new MainPageStrings();
private readonly RegExStrings _regex = new RegExStrings();
private readonly SettingsStrings _settings = new SettingsStrings();
Expand Down Expand Up @@ -69,6 +70,11 @@ public partial class LanguageManager : ObservableObject
/// </summary>
public JsonYamlStrings JsonYaml => _jsonyaml;

/// <summary>
/// Gets the <see cref="JwtDecoderEncoderStrings"/>.
/// </summary>
public JwtDecoderEncoderStrings JwtDecoderEncoder => _jwtdecoderencoder;

/// <summary>
/// Gets the <see cref="MainPageStrings"/>.
/// </summary>
Expand Down Expand Up @@ -437,6 +443,71 @@ public class JsonYamlStrings : ObservableObject
public string YamlToJson => _resources.GetString("YamlToJson");
}

public class JwtDecoderEncoderStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("JwtDecoderEncoder");

/// <summary>
/// Gets the resource Configuration.
/// </summary>
public string Configuration => _resources.GetString("Configuration");

/// <summary>
/// Gets the resource ConversionDescription.
/// </summary>
public string ConversionDescription => _resources.GetString("ConversionDescription");

/// <summary>
/// Gets the resource ConversionTitle.
/// </summary>
public string ConversionTitle => _resources.GetString("ConversionTitle");

/// <summary>
/// Gets the resource Decode.
/// </summary>
public string Decode => _resources.GetString("Decode");

/// <summary>
/// Gets the resource DisplayName.
/// </summary>
public string DisplayName => _resources.GetString("DisplayName");

/// <summary>
/// Gets the resource Encode.
/// </summary>
public string Encode => _resources.GetString("Encode");

/// <summary>
/// Gets the resource EncodingDescription.
/// </summary>
public string EncodingDescription => _resources.GetString("EncodingDescription");

/// <summary>
/// Gets the resource EncodingTitle.
/// </summary>
public string EncodingTitle => _resources.GetString("EncodingTitle");

/// <summary>
/// Gets the resource HeaderLabel.
/// </summary>
public string HeaderLabel => _resources.GetString("HeaderLabel");

/// <summary>
/// Gets the resource JwtTokenLabel.
/// </summary>
public string JwtTokenLabel => _resources.GetString("JwtTokenLabel");

/// <summary>
/// Gets the resource PayloadLabel.
/// </summary>
public string PayloadLabel => _resources.GetString("PayloadLabel");

/// <summary>
/// Gets the resource SecurityLabel.
/// </summary>
public string SecurityLabel => _resources.GetString("SecurityLabel");
}

public class MainPageStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("MainPage");
Expand Down
1 change: 1 addition & 0 deletions src/dev/impl/DevToys/Properties/Default.rd.rd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-->
<Namespace Name="Microsoft.Toolkit.Mvvm" Dynamic="Required All" />
<Namespace Name="DevToys" Dynamic="Required All" />
<Namespace Name="System.IdentityModel.Tokens.Jwt" Dynamic="Required All"/>

<!-- Add your application specific runtime directives here. -->
</Application>
Expand Down
156 changes: 156 additions & 0 deletions src/dev/impl/DevToys/Strings/en/JwtDecoderEncoder.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?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="Configuration" xml:space="preserve">
<value>Configuration</value>
</data>
<data name="ConversionDescription" xml:space="preserve">
<value>Select which action you want to use</value>
</data>
<data name="ConversionTitle" xml:space="preserve">
<value>Action</value>
</data>
<data name="Decode" xml:space="preserve">
<value>Decode</value>
</data>
<data name="DisplayName" xml:space="preserve">
<value>JWT Decoder</value>
</data>
<data name="Encode" xml:space="preserve">
<value>Encode</value>
</data>
<data name="EncodingDescription" xml:space="preserve">
<value>Select which encoding algorithm you want to use</value>
</data>
<data name="EncodingTitle" xml:space="preserve">
<value>Encoding</value>
</data>
<data name="HeaderLabel" xml:space="preserve">
<value>Header</value>
</data>
<data name="JwtTokenLabel" xml:space="preserve">
<value>Jwt Token</value>
</data>
<data name="PayloadLabel" xml:space="preserve">
<value>Payload</value>
</data>
<data name="SecurityLabel" xml:space="preserve">
<value>Security</value>
</data>
</root>
Loading

0 comments on commit 06f3898

Please sign in to comment.