File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
aspnetcore/security/authentication/configure-oidc-web-authentication/sample/oidc-net8/RazorPageOidc/Pages Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ @page
2+ @model RazorPageOidc .Pages .LoginModel
3+ @{
4+ }
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Authentication ;
2+ using Microsoft . AspNetCore . Authorization ;
3+ using Microsoft . AspNetCore . Mvc ;
4+ using Microsoft . AspNetCore . Mvc . RazorPages ;
5+
6+ namespace RazorPageOidc . Pages ;
7+
8+ [ AllowAnonymous ]
9+ public class LoginModel : PageModel
10+ {
11+ [ BindProperty ( SupportsGet = true ) ]
12+ public string ? ReturnUrl { get ; set ; }
13+
14+ public async Task OnGetAsync ( )
15+ {
16+ var properties = GetAuthProperties ( ReturnUrl ) ;
17+ await HttpContext . ChallengeAsync ( properties ) ;
18+ }
19+
20+ private static AuthenticationProperties GetAuthProperties ( string ? returnUrl )
21+ {
22+ const string pathBase = "/" ;
23+
24+ // Prevent open redirects.
25+ if ( string . IsNullOrEmpty ( returnUrl ) )
26+ {
27+ returnUrl = pathBase ;
28+ }
29+ else if ( ! Uri . IsWellFormedUriString ( returnUrl , UriKind . Relative ) )
30+ {
31+ returnUrl = new Uri ( returnUrl , UriKind . Absolute ) . PathAndQuery ;
32+ }
33+ else if ( returnUrl [ 0 ] != '/' )
34+ {
35+ returnUrl = $ "{ pathBase } { returnUrl } ";
36+ }
37+
38+ return new AuthenticationProperties { RedirectUri = returnUrl } ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments