Hello,
Hope you are doing well and not so good that my responses are not that clear. The second blog already answered your second question.
E.g. your question:
2. Also my Reply URL is something like "">WebBaseURL:8080/.../". Does it necessarily have to be HTTPS and not HTTP?
My answer:
It must have the following format: https ://PublicWeBaseUrl/OAuthLanding.htm. The PublicWebBaseUrl is the url to the WebClientInstance.
So yes, it must be set to https. You can use a trusted cert for this (recommended in productive environments) or a self signed cert (not recommended in productive environment, but OK for a Sandbox).
Related to the user_impersonation part.
In App Registration in Azure, go to Expose an API. Click on Add a scope. Typically it will have a format like api://guid. Under Scopes, click on the the created api. This opens the Add a scope screen. Under scope name type in user_impersonation. Who can consent is a business decision, only Admins (users will have to ask an Admin account or Admins and Users). Type in display name, etc. When done, click on Add scope.
Now go API permissions. By default you do not see the new scope you created. You will have to add it by clicking on Add a permissions. Then select My API's. If you just created the scope, it may not be visible immediately. Usually it can take a minute or two. Here you will see the name of the Azure AD app with the application client ID that is written after api://application (client) ID.
Note that the apiL//application (client) ID needs to be set in AppID Uri in customsettings.config file:
<add key="AppIdUri" value="api://application (client) ID" />
And it is similar to wtrealm value:
<add key="WSFederationLoginEndpoint" value="https ://login.microsoftonline.com/domainname/wsfed?wa=wsignin1.0%26wtrealm=api://application (client) ID" /> " />
Note that that wreply value has become obsolete, this is no longer required. The wreply value is however similar to the PublicWebBaseUrl plus /SignIn.
If you end up with Microsoft support to receive direct assistance, I usually ask the partner if they are good in doing a puzzle. The values must be similar and be exactly the same and used in the correct values of specific keys. If not, this error may happen.
Hope it is now more clear.