@@ -38,22 +38,20 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
38
38
var principal = new ClaimsPrincipal ( identity ) ;
39
39
var ticket = new AuthenticationTicket ( principal , properties , Scheme . Name ) ;
40
40
41
- // Return the authentication ticket as-is if the
42
- // user information endpoint has not been set.
41
+ // Return the authentication ticket as-is if the user information endpoint has not been set.
43
42
if ( string . IsNullOrEmpty ( Options . UserInformationEndpoint ) )
44
43
{
45
44
Logger . LogInformation ( "The userinfo request was skipped because no userinfo endpoint was configured." ) ;
46
45
47
- return ticket ;
46
+ return await RunAuthenticatedEventAsync ( ) ;
48
47
}
49
48
50
- // Return the authentication ticket as-is
51
- // if the application key has not been set.
49
+ // Return the authentication ticket as-is if the application key has not been set.
52
50
if ( string . IsNullOrEmpty ( Options . ApplicationKey ) )
53
51
{
54
52
Logger . LogInformation ( "The userinfo request was skipped because no application key was configured." ) ;
55
53
56
- return ticket ;
54
+ return await RunAuthenticatedEventAsync ( ) ;
57
55
}
58
56
59
57
// Note: prior to April 2018, the Steam identifier was prefixed with an HTTP base address.
@@ -68,12 +66,12 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
68
66
identifier = identifier . Substring ( SteamAuthenticationConstants . Namespaces . LegacyIdentifier . Length ) ;
69
67
}
70
68
71
- // Return the authentication ticket as-is if the claimed identifier is malformed.
69
+ // Prevent the sign-in operation from completing if the claimed identifier is malformed.
72
70
else
73
71
{
74
72
Logger . LogWarning ( "The userinfo request was skipped because an invalid identifier was received: {Identifier}." , identifier ) ;
75
73
76
- return ticket ;
74
+ throw new InvalidOperationException ( $ "The OpenID claimed identifier ' { identifier } ' is not valid." ) ;
77
75
}
78
76
79
77
var address = QueryHelpers . AddQueryString ( Options . UserInformationEndpoint , new Dictionary < string , string >
@@ -95,7 +93,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
95
93
/* Headers: */ response . Headers . ToString ( ) ,
96
94
/* Body: */ await response . Content . ReadAsStringAsync ( ) ) ;
97
95
98
- return ticket ;
96
+ throw new HttpRequestException ( "An error occurred while retrieving the user profile from Steam." ) ;
99
97
}
100
98
101
99
var payload = JObject . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
@@ -110,22 +108,27 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
110
108
identity . AddClaim ( new Claim ( ClaimTypes . Name , profile , ClaimValueTypes . String , Options . ClaimsIssuer ) ) ;
111
109
}
112
110
113
- var context = new OpenIdAuthenticatedContext ( Context , Scheme , Options , ticket )
114
- {
115
- User = payload
116
- } ;
111
+ return await RunAuthenticatedEventAsync ( payload ) ;
117
112
118
- // Copy the attributes to the context object.
119
- foreach ( var attribute in attributes )
113
+ async Task < AuthenticationTicket > RunAuthenticatedEventAsync ( JObject user = null )
120
114
{
121
- context . Attributes . Add ( attribute ) ;
115
+ var context = new OpenIdAuthenticatedContext ( Context , Scheme , Options , ticket )
116
+ {
117
+ User = user ?? new JObject ( )
118
+ } ;
119
+
120
+ // Copy the attributes to the context object.
121
+ foreach ( var attribute in attributes )
122
+ {
123
+ context . Attributes . Add ( attribute ) ;
124
+ }
125
+
126
+ await Events . Authenticated ( context ) ;
127
+
128
+ // Note: return the authentication ticket associated
129
+ // with the notification to allow replacing the ticket.
130
+ return context . Ticket ;
122
131
}
123
-
124
- await Events . Authenticated ( context ) ;
125
-
126
- // Note: return the authentication ticket associated
127
- // with the notification to allow replacing the ticket.
128
- return context . Ticket ;
129
132
}
130
133
131
134
private new OpenIdAuthenticationEvents Events => ( OpenIdAuthenticationEvents ) base . Events ;
0 commit comments