Skip to content

Commit

Permalink
Merge pull request #2 from curityio/feature/guides
Browse files Browse the repository at this point in the history
Fixed code to have working endpoints and to work with Visual Studio 2019
  • Loading branch information
gary-archer committed Apr 21, 2021
2 parents b3fa2e9 + bf76bd0 commit d0ec4b8
Show file tree
Hide file tree
Showing 9 changed files with 1,094 additions and 44 deletions.
1,023 changes: 1,023 additions & 0 deletions .vs/example-dotnet-openid-connect-client/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added UpgradeLog.htm
Binary file not shown.
11 changes: 9 additions & 2 deletions example-dotnet-openid-connect-client.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-dotnet-openid-connect-client", "example-dotnet-openid-connect-client\example-dotnet-openid-connect-client.csproj", "{EE8C3DEC-F0F2-4AE4-81A0-58359117602E}"
EndProject
Global
Expand All @@ -14,4 +15,10 @@ Global
{EE8C3DEC-F0F2-4AE4-81A0-58359117602E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE8C3DEC-F0F2-4AE4-81A0-58359117602E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8166D316-2134-441E-B026-08A4A6DA31C2}
EndGlobalSection
EndGlobal
7 changes: 6 additions & 1 deletion example-dotnet-openid-connect-client/App_Start/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Configuration;
using System.Net;
using System.Net.Http;
using Newtonsoft.Json.Linq;

Expand All @@ -25,6 +26,8 @@ public class AppConfig

private AppConfig()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

client_id = ConfigurationManager.AppSettings["client_id"];
client_secret = ConfigurationManager.AppSettings["client_secret"];
redirect_uri = ConfigurationManager.AppSettings["redirect_uri"];
Expand All @@ -42,7 +45,6 @@ private AppConfig()
{
var discoveryClient = new HttpClient();


var response = discoveryClient.GetAsync(issuer + "/.well-known/openid-configuration").Result;
if (response.IsSuccessStatusCode)
{
Expand All @@ -52,12 +54,15 @@ private AppConfig()
authorization_endpoint = responseJson["authorization_endpoint"].ToString();
token_endpoint = responseJson["token_endpoint"].ToString();
revocation_endpoint = responseJson["revocation_endpoint"].ToString();
logout_endpoint = responseJson["end_session_endpoint"].ToString();
jwks_uri = responseJson["jwks_uri"].ToString();

}
}
}



public String GetLogoutEndpoint()
{
return logout_endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
* limitations under the License.
*/

using System.Web;
using System.Web.Mvc;

namespace exampledotnetopenidconnectclient.Controllers
{
public class LogoutController : Controller
{
private static string client_id = App_Start.AppConfig.Instance.GetClientId();
private static string logout_endpoint = App_Start.AppConfig.Instance.GetLogoutEndpoint();
private static string base_url = App_Start.AppConfig.Instance.GetBaseUrl();

public ActionResult Index()
{
Session.Abandon();

return Redirect(logout_endpoint);
string logout_request = $"{logout_endpoint}?client_id={client_id}&post_logout_redirect_uri={HttpUtility.UrlEncode(base_url)}";
return Redirect(logout_request);
}
}
}
7 changes: 3 additions & 4 deletions example-dotnet-openid-connect-client/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@

<p class="text-default">This is a demo application to demonstrate the use for OAuth2 and OpenID Connect. </p>

<p class="text-default">Pressing Sign In will redirect you to @ViewData["server_name"] and authorize
<p class="text-default">Pressing Sign In will redirect you to sign in and authorize
the application to access your profile info. The data will only be used to
demonstrate
the possibilities of the OpenID Connect
protocol and will not be stored. Be sure to revoke access when you are satisfied.</p>
demonstrate the possibilities of the OpenID Connect protocol and will not be stored.
Be sure to revoke access when you are satisfied.</p>
<div class="center-block">
<a class="btn btn-primary center-block" style="display: block; width: 200px" role="button" href="/login">Sign In</a>
</div>
Expand Down
33 changes: 16 additions & 17 deletions example-dotnet-openid-connect-client/Web.config
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="client_id" value="client-dotnet" />
<add key="client_secret" value="Password1" />
<add key="redirect_uri" value="http:https://localhost:5443/callback" />
<add key="scope" value="openid read" />
<add key="authorization_endpoint" value="" />
<add key="token_endpoint" value="" />
<add key="logout_endpoint" value="https://nordicapis.curity.io/authn/authenticate/logout?redirect_uri=http:https://localhost:5443" />
<add key="revocation_endpoint" value="" />
<add key="jwks_uri" value="" />
<add key="issuer" value="https://nordicapis.curity.io/~" />
<add key="api_endpoint" value="https://nordicapis-api.curity.io/hello_world" />
<add key="base_url" value="http:https://localhost:5443" />
<add key="client_id" value="client-dotnet"/>
<add key="client_secret" value="Password1"/>
<add key="redirect_uri" value="http:https://localhost:5443/callback"/>
<add key="scope" value="openid read"/>
<add key="authorization_endpoint" value=""/>
<add key="token_endpoint" value=""/>
<add key="logout_endpoint" value=""/>
<add key="revocation_endpoint" value=""/>
<add key="jwks_uri" value=""/>
<add key="issuer" value="https://localhost:8443/oauth/v2/oauth-anonymous"/>
<add key="api_endpoint" value="https://localhost:3000"/>
<add key="base_url" value="http:https://localhost:5443"/>
</appSettings>
<system.web>
<compilation>
<assemblies>
</assemblies>
<compilation debug="true">
<assemblies/>
</compilation>
</system.web>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http:https://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,6 +9,18 @@
<RootNamespace>exampledotnetopenidconnectclient</RootNamespace>
<AssemblyName>example-dotnet-openid-connect-client</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -90,7 +102,6 @@
<Folder Include="Content\" />
<Folder Include="Models\" />
<Folder Include="Scripts\" />
<Folder Include="Helpers\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
Expand Down Expand Up @@ -126,5 +137,24 @@
</Policies>
</Properties>
</MonoDevelop>
<VisualStudio>
<FlavorProperties GUID="{349C5851-65DF-11DA-9384-00065B846F21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http:https://localhost:5443/</IISUrl>
<OverrideIISAppRootUrl>True</OverrideIISAppRootUrl>
<IISAppRootUrl>http:https://localhost:5443/</IISAppRootUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />
</Project>

This file was deleted.

0 comments on commit d0ec4b8

Please sign in to comment.