Create AppToken by API

Hi,
is it possible to create an identical AppToken within multiple instances of PSU? This would make it easier to connect to e.g. the integration and production instance…

I’ve already tried to create one by API POST /api/v1/apptoken… The API call succeeds but the created token is “invalid” if I use it in the API again.

Product: PowerShell Universal
Version: 1.5.21

This seems like a bug with the POST endpoint. I’ll open an issue for this to see if we can get that fixed.

Can you share your HTTP calls? I tried this locally and can’t reproduce it.

PUT  {{baseUrl}}/apptoken
content-type: {{contentType}}
Authorization: Bearer {{appToken}}

{
  "id": 7,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiRGVmYXVsdCBBZG1pbiIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2hhc2giOiI4NGUzYmIzMi1hMzU1LTQ4MjMtOTNhNi01YzRmNjliYTc5ZWMiLCJzdWIiOiJQb3dlclNoZWxsVW5pdmVyc2FsIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5pc3RyYXRvciIsIm5iZiI6MTYyNjA3NDMzNCwiZXhwIjoxNjI4NjY2MzM0LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.SPer4mhQhuc_l9dE5uZj03T7XuVGYlaRdMnERiay#Pg",
  "identity": {
    "id": 1,
    "name": "Default Admin",
    "source": 0,
    "role": null,
    "roleName": null
  },
  "revoked": false,
    "role": "Administrator",
    "created": "2021-07-12T09:18:54.898+02:00",
    "expiration": "2021-08-11T09:18:54.881+02:00",
    "revokedDate": "0001-01-01T00:00:00",
    "createdBy": {
      "id": 1,
      "name": null,
      "source": 0,
      "role": null,
      "roleName": null
    }
  }
}

Hi,
Any insights?

-Sascha aka callidus2000
(finally back from vacation)

I’d suggest trying to remove the ID so it creates a new ID. Have you updated the appsettings.json file at all? Particularly this section is used for generating app tokens.

  "Jwt": {  
    "SigningKey": "PleaseUseYourOwnSigningKeyHere",  
    "Issuer": "IronmanSoftware",
    "Audience": "PowerShellUniversal"
  },

Hi,
The JWT settings are currently untouched.
if I remove the “id” then it automatically sets it to id=0.

PUT  {{baseUrl}}/apptoken
content-type: {{contentType}}
Authorization: Bearer {{appToken}}

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiRGVmYXVsdCBBZG1pbiIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2hhc2giOiI2MmQ0OTc1Ni05YjZlLTQxZGYtYjA4ZS1iOWVhZWI0NWQ3YTIiLCJzdWIiOiJQb3dlclNoZWxsVW5pdmVyc2FsIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5pc3RyYXRvciIsIm5iZiI6MTYzMDM5MzQ3NiwiZXhwIjoxNjYxOTI5NDc2LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.12FUuieJGSLHvvUuf6PCkSaK9faA4QMl8K1ovsnmwek",
  "identity": {
    "id": 1,
    "name": "Default Admin",
    "source": 0,
    "role": null,
    "roleName": null
  },
  "revoked": false,
    "role": "Administrator",
    "created": "2021-07-12T09:18:54.898+02:00",
    "expiration": "2030-08-11T09:18:54.881+02:00",
    "revokedDate": "0001-01-01T00:00:00",
    "createdBy": {
      "id": 1,
      "name": null,
      "source": 0,
      "role": null,
      "roleName": null
    }
  }
}

results in the following response:

HTTP/1.1 200 OK
Connection: close
Date: Tue, 31 Aug 2021 06:38:05 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding

{
  "id": 0,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiRGVmYXVsdCBBZG1pbiIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2hhc2giOiI2MmQ0OTc1Ni05YjZlLTQxZGYtYjA4ZS1iOWVhZWI0NWQ3YTIiLCJzdWIiOiJQb3dlclNoZWxsVW5pdmVyc2FsIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5pc3RyYXRvciIsIm5iZiI6MTYzMDM5MzQ3NiwiZXhwIjoxNjYxOTI5NDc2LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.12FUuieJGSLHvvUuf6PCkSaK9faA4QMl8K1ovsnmwek",
  "identity": {
    "id": 1,
    "name": "Default Admin",
    "source": 0,
    "role": null,
    "roleName": null
  },
  "revoked": false,
  "role": "Administrator",
  "created": "2021-07-12T09:18:54.898+02:00",
  "expiration": "2030-08-11T09:18:54.881+02:00",
  "revokedDate": "0001-01-01T00:00:00",
  "createdBy": {
    "id": 1,
    "name": null,
    "source": 0,
    "role": null,
    "roleName": null
  }
}

If I try to use this newly created token

GET  {{baseUrl}}/apptoken
content-type: {{contentType}}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiRGVmYXVsdCBBZG1pbiIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2hhc2giOiI2MmQ0OTc1Ni05YjZlLTQxZGYtYjA4ZS1iOWVhZWI0NWQ3YTIiLCJzdWIiOiJQb3dlclNoZWxsVW5pdmVyc2FsIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5pc3RyYXRvciIsIm5iZiI6MTYzMDM5MzQ3NiwiZXhwIjoxNjYxOTI5NDc2LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.12FUuieJGSLHvvUuf6PCkSaK9faA4QMl8K1ovsnmwek

all I get an unauthorized error:

HTTP/1.1 401 Unauthorized
Connection: close
Date: Tue, 31 Aug 2021 06:37:13 GMT
Server: Kestrel
Content-Length: 0
Location: http://localhost:5000/login?ReturnUrl=%2Fapi%2Fv1%2Fapptoken
WWW-Authenticate: Bearer error="invalid_token", Bearer error="invalid_token"