Authentication - Dashboard and REST API

Hi all,

is there a way to get the dashboard and REST API running on the same port with the same authentication method?
I created a login page for the dashboard which uses the Form authentication way.
Now if I use the parameter Endpoint from Start-UDDashboard, only the dashboard authenticates well whilst the rest api returns the error “Bad username or password”

Thanks.

Hi guys,

nothing on this?

Thanks.

Hey @Brunogr,

Sorry for the delay. You should install the latest nightly build. This is possible. You can pass in 2 authenticationMethod objects to your REST API. Here’s an example.

        $auth = @()
        $auth += New-UDAuthenticationMethod -Endpoint {
                param([PSCredential]$Credential)
                $userName = $Credential.UserName
                $role = if ($userName -eq 'Adam') {
                    'admin'
                } else {
                    'luser'
                }
                $Token = Grant-UDJsonWebToken -Identity $UserName -Role $Role -Issuer 'Adam'
                New-UDAuthenticationResult -Success -UserName $userName -Role $role -ErrorMessage '' -Token $Token
            }
        $auth += New-UDAuthenticationMethod -Issuer 'Adam'

        $endpoint = New-UDEndpoint -Url /authtest -Endpoint {
            $User
        }

        $Server = Start-UDRestApi -Port 10001 -AuthenticationMethod $auth -Endpoint $endpoint


            $uri = 'http://localhost:10001/login'
            $Result = Invoke-RestMethod -Uri $uri -Method POST -Body (@{ username = "Adam"; password = "Test" } | ConvertTo-Json) -SessionVariable "Session"
            $uri = 'http://localhost:10001/api/authtest'
            Invoke-RestMethod -Uri $uri -Method GET -Headers @{ Authorization = "Bearer $($Result.Token)"} | Should be "Adam"
        

It now works… Thanks a lot @adam