The followings are the main cause for "The remote server returned 401 unauthorized exception". Check the below scenarios:
1. Client ID, ISSUER ID must be in small case and not in Upper case and also check the space in web.config file.
2. Certificate date should not be expired- check the expiration details.
3. Go to registry settings and check below settings:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Right-click MSV1_0, point to New, and then click Multi-String Value.
Type BackConnectionHostNames, and then press ENTER.
Right-click BackConnectionHostNames, and then click Modify.
In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK
Disable the loopback check (less-recommended method)
a. The second method is to disable the loopback check by setting the DisableLoopbackCheck registry key.
To set the DisableLoopbackCheck registry key, follow these steps:
b. Set the DisableStrictNameChecking registry entry to 1
Click Start, click Run, type regedit, and then click OK.
In Registry Editor, locate and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Right-click Lsa, point to New, and then click DWORD Value.
Type DisableLoopbackCheck, and then press ENTER.
Right-click DisableLoopbackCheck, and then click Modify.
In the Value data box, type 1, and then click OK.
i. Quit Registry Editor, and then restart your computer.