< Summary

Information
Class: Utility.Components.JWTDebugger.JWTDebugger
Assembly: Utility
File(s): /home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/JWTDebugger/JWTDebugger.razor
Tag: 231_14069517506
Line coverage
63%
Covered lines: 12
Uncovered lines: 7
Coverable lines: 19
Total lines: 87
Line coverage: 63.1%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Input()100%11100%
get_Output()100%210%
get_Header()100%11100%
get_Payload()100%11100%
get_Signature()100%11100%
Decode()100%22100%
Clear()100%210%
Copy()100%210%

File(s)

/home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/JWTDebugger/JWTDebugger.razor

#LineLine coverage
 1@using System.Text
 2@using System.IdentityModel.Tokens.Jwt
 3@inject IJSRuntime JSRuntime
 4
 5<div class="container">
 6    <div class="row">
 7        <div class="col">
 8            <h2>JWT Debugger</h2>
 9        </div>
 10    </div>
 11
 12    <div class="row">
 13        <div class="col">
 14            <label class="label-control" for="algorithm-select">Algorithm:</label>
 15            <select id="algorithm-select" name="algorithm-select" class="form-control" >
 16                <option name="algorithm" value="HS256" selected="">HS256</option>
 17            </select>
 18        </div>
 19    </div>
 20
 21    <div class="row">
 22        <div class="col">
 23            <div class="input-group">
 24                <textarea id="Input" class="form-control" rows="5" @bind="Input" placeholder="JWT"></textarea>
 25                <span class="input-group-btn">
 26                    <button id="btnDecode" name="btnDecode" class="btn btn-success" @onclick="Decode"><i class="fas fa-a
 27                    <button id="btnClear" name="btnClear" class="btn btn-danger float-right" @onclick="Clear"><i class="
 28                </span>
 29            </div>
 30        </div>
 31        <div class="col">
 32            <p>HEADER:ALGORITHM & TOKEN TYPE</p>
 33            <textarea id="Header" class="form-control" rows="5" @bind="Header" placeholder="DECODED"></textarea>
 34            <p>PAYLOAD:DATA</p>
 35            <textarea id="Payload" class="form-control" rows="5" @bind="Payload" placeholder="DECODED"></textarea>
 36            <p>VERIFY SIGNATURE</p>
 37            <textarea id="VerifySignature" class="form-control" rows="5" @bind="Signature" placeholder="DECODED"></texta
 38        </div>
 39    </div>
 40
 41    <div class="row">
 42        <div class="col">
 43            <p>Inspired from <a href="https://jwt.io" target="_blank">JWT.io</a>.</p>
 44        </div>
 45    </div>
 46
 47</div>
 48
 49@code {
 50    [Parameter]
 851    public string? Input { get; set; }
 52
 53    [Parameter]
 054    public string? Output { get; set; }
 55
 56    [Parameter]
 657    public string Header { get; set; }
 58
 59    [Parameter]
 660    public string Payload { get; set; }
 61
 62    [Parameter]
 663    public string Signature { get; set; }
 64
 65    // protected override void OnInitialized() {}
 66
 67    void Decode()
 168    {
 169        if (string.IsNullOrEmpty(Input)) return;
 70
 171        var handler = new JwtSecurityTokenHandler();
 172        var jwtSecurityToken = handler.ReadJwtToken(Input);
 173        Header = jwtSecurityToken.Header.SerializeToJson();
 174        Payload = jwtSecurityToken.Payload.SerializeToJson();
 175        Signature = jwtSecurityToken.RawSignature;
 176    }
 77
 78    private void Clear()
 079    {
 080        Input = string.Empty;
 081    }
 82
 83    async Task Copy()
 084    {
 085        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output);
 086    }
 87}