kgrzybek / modular-monolith-with-ddd

Full Modular Monolith application with Domain-Driven Design approach.
MIT License
11.12k stars 1.75k forks source link

Steps to Obtaining OAuth 2.0 Token #45

Closed 274188A closed 4 years ago

274188A commented 4 years ago

I'm fairly new to token tech but I have tried to use Postman to send a POST with simply query strings to get an OAuth2 token (below) using the method shown here.

I'm seeing this error in postman console log:

Error: Could not complete OAuth 2.0 token request: {"":""}

I think I'm missing something - but is there an endpoint for doing Auth?
I have used /oauth/token but probably not correct but best guess

https://localhost:5000/oauth/token/?grant_type=password&username=testMember@mail.com&password=testMemberPass&client_id=ro.client&client_secret=secret

I'm happy to help write up/clarify some baby steps if needed :-)

kgrzybek commented 4 years ago

Hi @274188A

You should follow the instructions included in README:

https://github.com/kgrzybek/modular-monolith-with-ddd#5-how-to-run

There are detailed description how to obtain the token :)

DavudSafarli commented 4 years ago

Hi. Following the instructions in README, which is taken from identityserver docs:

POST /connect/token HTTP/1.1
Host: localhost:5000

grant_type=password
&username=testMember@mail.com
&password=testMemberPass
&client_id=ro.client
&client_secret=secret

I keep getting

{
  "error": "invalid_request"
}
VantageKR commented 4 years ago

I find the simplest way to get the token is with Powershell:

$ids_host = "http://localhost:5000"
$connect_token_endpoint = "$ids_host/connect/token"
$response = (curl.exe -d "grant_type=password&username=$login&password=$password&client_id=ro.client&client_secret=secret" $connect_token_endpoint) | Out-String
$json = $response | ConvertFrom-Json
$access_token = $($json.access_token)

Hope that helps. I think curl does a POST by default.

DavudSafarli commented 4 years ago

Issue for me was incorrect database connection string. After checking logs/fixing connection string, making Form request gave the correct response. If you are using Insomnia for API client: image