Generate GroupShare token via API

Hello,

I'm trying to connect to the GroupShare API in c# and am having some trouble. I'm getting the 401 authentication error. In the API it is stated that the header should be set to "Basic" and the values for username and password should be encoded in Base64. Unfortunately after many attempts, I can't figure out how this is in terms of key/ value in the header of the request. I would be grateful if anyone knows the content of the header data for the authorisation.

Thanks, Fil.

Parents
  • Hi Filip,

    Find below my code for getting the token in PowerShell, which hopefully helps. I have no C# know-how, so can't share any C# code with you.

    Once you have the token, you can use that for subsequent calls:

    function Get-Token

    {

       param ($server, $username, $password)

       $user = "$username"

       $pass = "$password"

       $EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($user + ':' + $pass)

       $EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)

       $tokenheader = @{"Authorization"="Basic $($EncodedPassword)"}

       $tokenurl = "http://${server}/authentication/api/0.7/login/"

       $tokencontentType = "application/json"

       $tokenbody = ConvertTo-Json @("ManagementRestApi")

       $token = Invoke-RestMethod -Method Post -Headers $tokenheader -ContentType $tokencontentType -Uri $tokenurl -Body $tokenbody

       ConvertTo-Json $token | ConvertFrom-Json

    }

    Cheers,

    Best regards,
    Luis Lopes | Principal Product Manager | RWS | (twitter) @Luis___Lopes |

Reply
  • Hi Filip,

    Find below my code for getting the token in PowerShell, which hopefully helps. I have no C# know-how, so can't share any C# code with you.

    Once you have the token, you can use that for subsequent calls:

    function Get-Token

    {

       param ($server, $username, $password)

       $user = "$username"

       $pass = "$password"

       $EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($user + ':' + $pass)

       $EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)

       $tokenheader = @{"Authorization"="Basic $($EncodedPassword)"}

       $tokenurl = "http://${server}/authentication/api/0.7/login/"

       $tokencontentType = "application/json"

       $tokenbody = ConvertTo-Json @("ManagementRestApi")

       $token = Invoke-RestMethod -Method Post -Headers $tokenheader -ContentType $tokencontentType -Uri $tokenurl -Body $tokenbody

       ConvertTo-Json $token | ConvertFrom-Json

    }

    Cheers,

    Best regards,
    Luis Lopes | Principal Product Manager | RWS | (twitter) @Luis___Lopes |

Children