Getting Nuget packages for base64url encoding

Tagged: , , ,

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Max Kozlov Max Kozlov 3 months, 1 week ago.

  • Author
    Posts
  • #60513
    Profile photo of i255d
    i255d
    Participant

    I am working on configuring a JWT (JSON Web Token) for connection to Box. I am hoping to make it so others can use this when I am done.

    I got these packages from Nuget for the encoder:
    https://www.nuget.org/packages/Microsoft.Owin.Security/3.0.1
    https://www.nuget.org/packages/Microsoft.Owin/
    https://www.nuget.org/packages/Owin/

    I know I can download the Nuget cli tool with this command:
    choco install nuget.commandline /y /f

    I used Visual Studio to make these packages available, and then pulled them into PowerShell like this:

    #MS Owin for base64url encoding
    $Owin = 'C:\folder\tf\DevOps\Box\BoxConnect\packages\Owin.1.0\lib\net40\Owin.dll'
    $msOwin = 'C:\folder\tf\DevOps\Box\BoxConnect\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll'
    $msOwinSec = 'C:\folder\tf\DevOps\Box\BoxConnect\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll'
    Add-Type -Path $Owin 
    Add-Type -Path $msOwin
    Add-Type -Path $msOwinSec
    
    # get a base64url encoder object
    $encoder = New-Object Microsoft.Owin.Security.DataHandler.Encoder.Base64UrlTextEncoder

    What I want to know, is could I have made those packages available using PowerShell or the Nuget CLI through PowerShell?

  • #60526
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    you dont need external classes to work with uri's
    Uri Class
    https://msdn.microsoft.com/en-us/library/system.uri(v=vs.110).aspx

    Convert.ToBase64String Method (Byte[])
    https://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.110).aspx

    you only need to know the encoding rules

    • #60568
      Profile photo of i255d
      i255d
      Participant

      I don't know how to make that usable in PowerShell.

      Here is an example of what I am trying to do:

      #MS Owin for base64url encoding
      $Owin = 'C:\EEDevOps\TeamFoundation\DevOps\Box\BoxConnect\packages\Owin.1.0\lib\net40\Owin.dll'
      $msOwin = 'C:\EEDevOps\TeamFoundation\DevOps\Box\BoxConnect\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll'
      $msOwinSec = 'C:\EEDevOps\TeamFoundation\DevOps\Box\BoxConnect\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll'
      Add-Type -Path $Owin 
      Add-Type -Path $msOwin
      Add-Type -Path $msOwinSec
      
      # get a base64url encoder object
      $encoder = New-Object Microsoft.Owin.Security.DataHandler.Encoder.Base64UrlTextEncoder
      # we then serialize to UTF-8 bytes, then base64url encode the claims
      $header = $encoder.Encode([System.Text.Encoding]::UTF8.GetBytes($rawheader))
      $claims = $encoder.Encode([System.Text.Encoding]::UTF8.GetBytes($rawclaims))

      Can you walk me through how I can use what you are explaining?

  • #60616
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    I see your example in other topic, the blog post from which you get it and I still believe you don't need owin 🙂

    # instead of
    # [...]
    $encoder = New-Object Microsoft.Owin.Security.DataHandler.Encoder.Base64UrlTextEncoder
    $header = $encoder.Encode([System.Text.Encoding]::UTF8.GetBytes($rawheader))
    # you can use
    $header = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($rawheader)) -replace '='
    

    and get the same result

You must be logged in to reply to this topic.