Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit a947e4f

Browse files
OKTA-565412: create razor pages samples (#76)
- okta hosted - self hosted
1 parent 589b333 commit a947e4f

File tree

167 files changed

+149104
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+149104
-1
lines changed

samples-aspnetcore-6x/self-hosted-login/okta-aspnetcore-mvc-example/okta-aspnetcore-mvc-example.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Okta.AspNetCore" Version="4.2.1" />
11+
<PackageReference Include="Okta.AspNetCore" Version="4.4.2" />
1212
</ItemGroup>
1313

1414
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33213.308
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "okta-aspnetcore-razorpages-example", "okta-aspnetcore-razorpages-example\okta-aspnetcore-razorpages-example.csproj", "{A0F648AD-6EE4-49EF-BE0D-882642050DDE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A0F648AD-6EE4-49EF-BE0D-882642050DDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A0F648AD-6EE4-49EF-BE0D-882642050DDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A0F648AD-6EE4-49EF-BE0D-882642050DDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A0F648AD-6EE4-49EF-BE0D-882642050DDE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0FBA9FD8-EF95-4C5F-A8C1-7B24F2DEB076}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@page
2+
@model okta_aspnetcore_razorpages_example.Pages.Account.ProfileModel
3+
@{
4+
}
5+
6+
<h2>View claims</h2>
7+
8+
<dl class="dl-horizontal">
9+
@foreach (var claim in Model.Claims)
10+
{
11+
<dt title="@claim.Type">
12+
@claim.Type
13+
<button type="button"
14+
class="btn btn-link btn-xs"
15+
aria-label="Copy to clipboard"
16+
title="Copy to clipboard"
17+
data-clipboard-text="@claim.Value">
18+
<span class="glyphicon glyphicon glyphicon-copy" aria-hidden="true"></span>
19+
</button>
20+
</dt>
21+
22+
<dd id="[email protected]("{0}", claim.Type)">@claim.Value</dd>
23+
}
24+
</dl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace okta_aspnetcore_razorpages_example.Pages.Account
5+
{
6+
public class ProfileModel : PageModel
7+
{
8+
public void OnGet()
9+
{
10+
}
11+
12+
public IEnumerable<System.Security.Claims.Claim> Claims
13+
{
14+
get => User?.Claims;
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@page
2+
3+
@model okta_aspnetcore_razorpages_example.Pages.Account.SignInModel
4+
@{
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Authentication;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
using Okta.AspNetCore;
5+
6+
namespace okta_aspnetcore_razorpages_example.Pages.Account
7+
{
8+
public class SignInModel : PageModel
9+
{
10+
public async Task<IActionResult> OnGet()
11+
{
12+
if (!HttpContext.User.Identity.IsAuthenticated)
13+
{
14+
return Challenge(OktaDefaults.MvcAuthenticationScheme);
15+
}
16+
17+
return Redirect("/Index");
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@page
2+
@model okta_aspnetcore_razorpages_example.Pages.Account.SignOutModel
3+
@{
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Authentication.Cookies;
2+
using Microsoft.AspNetCore.Authentication;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.RazorPages;
5+
using Okta.AspNetCore;
6+
7+
namespace okta_aspnetcore_razorpages_example.Pages.Account
8+
{
9+
public class SignOutModel : PageModel
10+
{
11+
public async Task<IActionResult> OnGetAsync()
12+
{
13+
return new SignOutResult(
14+
new[]
15+
{
16+
OktaDefaults.MvcAuthenticationScheme,
17+
CookieAuthenticationDefaults.AuthenticationScheme,
18+
},
19+
new AuthenticationProperties { RedirectUri = "/Index" });
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace okta_aspnetcore_razorpages_example.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)