OpenIddict with external OAuth server

46 views Asked by At

I currently have an Auth Server built on top of OpenIddict, an API and a Blazor WASM client. I am using the code flow with refresh tokens. The Blazor app redirects the users for the login to the Auth Server, gets the tokens and uses them in the http client via a custom AuthorizationMessageHandler (in it's constructor it calls ConfigureHandler to set the authorized urls and the scope defined in my OpenIddict server for my API). All works fine.

In addition to the above, I now need to connect to an external OAuth server, that also uses the code flow, get some other tokens from there to be able to call an external API. I think I need to setup my OpenIddict via AddClient(), but I don't really understand where to set all the data. The URL for getting the authorization code is: https:///mercury/authorization/?response_type=code&client_id=&state=

where users will need to enter their user and password for that site.

Then I will need to make a POST call to another url with the code, some API KEY that needs to be put in the header of the POST, like so:

    curl --location --request POST 'https://xyz_something_else/oauth/v1/token' \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Basic <YOUR BASIC CREDENTIALS>' \
    --header 'X-API-KEY: <YOUR API KEY>' \
    --header 'User-Agent: <agent>'
    --data-raw '{
        "grant_type":"authorization_code",
        "code":"<CODE>"
    }

In order to update the token I need to make the following call:

    curl --location --request POST 'https://xyz_something_else/oauth/v1/token' \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Basic <YOUR BASIC CREDENTIALS>' \
    --header 'X-API-KEY: <YOUR API KEY>' \
    --header 'User-Agent: <agent>'
    --data-raw '{
        "grant_type":"refresh_token",
        "refresh_token":"<YOUR REFRESH TOKEN>"
    }

I don't understand how can I specify all this information to OpenIddict. Also, how do I attach a scope so that I can create another custom AuthorizationMessageHandler that uses the tokens from this external auth server, instead of the ones to be used with my api?

I've looked through all the samples from OpenIddict and their website. Also searched on google (including stackoverflow) :)

0

There are 0 answers