Q:

how to solve port issue between heroku and okta?

I have a nodejs app that uses okta services for authentication.
The app I tested locally on my pc and it works ok, it starts listening on port 3000:
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`App listening on port ${port}`))

So far so good.
Next step I deployed the app on heroku, but - unfortunately - it doesnt work...
I have inspected the log file and I found the culprit: it seems heroku ignores the port that I set in my .env file to 3000, and it uses a (random?) value for the port, 16709 for example:

2020-04-17T09:51:40.261031+00:00 app[web.1]: App listening on port
  16709

That explains why the authentication fails.
As I see in okta settings, it definitely expects port 3000:
Login redirect URIs : http://localhost:3000/authorization-code/callback 

So I'm stuck... I searched stackoverflow and I found this: How login with okta oauth in new heroku app , but unfortunately theres no answer :(
Please, anyone knows how to mitigate/solve this port issue between heroku and okta?

Update:
I tried the suggestions from the answer and comments below, but it still doesnt work...
What I get from okta auth is: 

"400 - bad request. You request resulted in an error. Identityy
  provider: Unknown. Error code: invalid_request."  

And here are some logs from okta:  

Outcome
Reason mismatched_redirect_uri
Result FAILURE

Severity WARN System
DebugContext
    DebugData
        AuthCode <removed by me>
        AuthorizationServer <removed by me>
        AuthorizationServerName default
        ClientAuthType client_secret_basic
        GrantType authorization_code
        GrantedScopes
        RedirectUri https://my_app.herokuapp.com//authorization-code/callback
        RequestId <removed by me>
        RequestUri /oauth2/default/v1/token
        RequestedScopes
        ThreatSuspected false
        Url /oauth2/default/v1/token?
LegacyEventType app.oauth2.as.token.grant_failure

A:

Well, by inspecting your okta logs, it seems you have an extra "/" in your redirect URL.
This is definitely the main cause of the failure "mismatched_redirect_uri".  
Please change this (note: double-slash before authorization-code):  
RedirectUri = https://my_app.herokuapp.com//authorization-code/callback

with this (note: single-slash before authorization-code):
RedirectUri = https://my_app.herokuapp.com/authorization-code/callback

After the above correction, just try to redo all the tests (login, auth, etc).
I'm 99% sure this will solve your issue.

