Coder Social home page Coder Social logo

posh-jwt's Introduction

PowerShell JWT

JWT (JSON Web Tokens) implementation in PowerShell

Many modern APIs require crytographically signed JWT tokens. This module is to enable utilising those from PowerShell. After the initial implementation using Windows PowerShell 5.1, version 1.1.0 has been successfully tested on Ubuntu and on Windows 10 with PowerShell Core 6.0.

Getting Started

The script module is published on PowerShell Gallery. If you're using PowerShell 5 or later, install with

Install-Module JWT

Alternatively, download the source and import the script module directly:

Import-Module \\Path\to\JWT.psm1

Usage

The module provides three functions: New-Jwt, Test-Jwt (also aliased to Verify-JwtSignature), and Get-JwtPayload.

New-Jwt creates a JWT given a claim and a signing key. Only "RS256" (RSA with SHA256) is supported in v. 1.1.0, so the optional header should not be changed:

# Windows example - using cert: drive
$jwt = New-Jwt -Cert (Get-ChildItem cert:\CurrentUser\My)[1] -PayloadJson '{"token1":"value1","token2":"value2"}'

Test-Jwt verifies a JWT provided certificate of the signing key:

$certx = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\ps\jwt\jwt.cer")
Test-Jwt -Jwt $jwt -Cert $certx

Get-JwtPayload decodes the payload part of the input JWT (usually JSON):

$jwt | Get-JwtPayload | ConvertFrom-JSON
token1 token2
------ ------
value1 value2

More advanced examples (taken directly from the code that started this effort) are found in the functions' help.

Compatibility Notes

In Windows, CSP is the legacy mechanism for providing cryptographic services. Not all CSPs provide the necessary functions - some don't support signing with SHA-256. To list available CSPs and their capabilities, run certutil.exe -csplist -v and check for entry for SHA-256. One CSP that supports it is Microsoft Enhanced RSA and AES Cryptographic Provider. To find the CSP used for a particular key, run

$cert.PrivateKey.CspKeyContainerInfo.ProviderName

Version 1.1.0 modifies the code to be compatible with RSA as well as CNG in WIndows and OpenSSL provider on Linux/Macintosh.

posh-jwt's People

Contributors

sp3269 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.