@@ -28,7 +28,6 @@ public static void UseAuth0Authentication(this IServiceCollection services, ICon
28
28
. AddCookie ( )
29
29
. AddOpenIdConnect ( "Auth0" , options =>
30
30
{
31
- // Set the authority to your Auth0 domain
32
31
var auth0 = configuration . GetSection ( "Auth0" ) . Get < Auth0Information > ( ) ;
33
32
options . Authority = $ "https://{ auth0 . Domain } ";
34
33
options . ClientId = auth0 . ClientId ;
@@ -48,33 +47,33 @@ public static void UseAuth0Authentication(this IServiceCollection services, ICon
48
47
49
48
options . Events = new OpenIdConnectEvents
50
49
{
51
- // handle the logout redirection
52
- OnRedirectToIdentityProviderForSignOut = context =>
53
- {
54
- var logoutUri = $ "https://{ auth0 . Domain } /v2/logout?client_id={ auth0 . ClientId } ";
55
-
56
- var postLogoutUri = context . Properties . RedirectUri ;
57
- if ( ! string . IsNullOrEmpty ( postLogoutUri ) )
58
- {
59
- if ( postLogoutUri . StartsWith ( "/" ) )
60
- {
61
- // transform to absolute
62
- var request = context . Request ;
63
- postLogoutUri = request . Scheme + "://" + request . Host + request . PathBase + postLogoutUri ;
64
- }
65
-
66
- logoutUri += $ "&returnTo={ Uri . EscapeDataString ( postLogoutUri ) } ";
67
- }
68
-
69
- context . Response . Redirect ( logoutUri ) ;
70
- context . HandleResponse ( ) ;
71
-
72
- return Task . CompletedTask ;
73
- } ,
50
+ OnRedirectToIdentityProviderForSignOut = context => HandleRedirect ( auth0 , context ) ,
74
51
} ;
75
52
} ) ;
76
53
77
54
services . AddHttpContextAccessor ( ) ;
78
55
services . AddScoped < ILoginManager , Auth0LoginManager > ( ) ;
79
56
}
80
- }
57
+
58
+ private static Task HandleRedirect ( Auth0Information auth0 , RedirectContext context )
59
+ {
60
+ var logoutUri = $ "https://{ auth0 . Domain } /v2/logout?client_id={ auth0 . ClientId } ";
61
+
62
+ var postLogoutUri = context . Properties . RedirectUri ;
63
+ if ( ! string . IsNullOrEmpty ( postLogoutUri ) )
64
+ {
65
+ if ( postLogoutUri . StartsWith ( "/" ) )
66
+ {
67
+ var request = context . Request ;
68
+ postLogoutUri = request . Scheme + "://" + request . Host + request . PathBase + postLogoutUri ;
69
+ }
70
+
71
+ logoutUri += $ "&returnTo={ Uri . EscapeDataString ( postLogoutUri ) } ";
72
+ }
73
+
74
+ context . Response . Redirect ( logoutUri ) ;
75
+ context . HandleResponse ( ) ;
76
+
77
+ return Task . CompletedTask ;
78
+ }
79
+ }
0 commit comments