This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
220ab84
commit 4611ac9
Showing
4 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/IdentityServer4/Events/TokenIntrospectionFailureEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using IdentityServer4.Extensions; | ||
using System.Collections.Generic; | ||
|
||
namespace IdentityServer4.Events | ||
{ | ||
/// <summary> | ||
/// Event for failed token introspection | ||
/// </summary> | ||
/// <seealso cref="IdentityServer4.Events.Event" /> | ||
public class TokenIntrospectionFailureEvent : Event | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TokenIntrospectionSuccessEvent" /> class. | ||
/// </summary> | ||
/// <param name="apiName">Name of the API.</param> | ||
/// <param name="errorMessage">The error message.</param> | ||
/// <param name="token">The token.</param> | ||
/// <param name="apiScopes">The API scopes.</param> | ||
/// <param name="tokenScopes">The token scopes.</param> | ||
public TokenIntrospectionFailureEvent(string apiName, string errorMessage, string token = null, IEnumerable<string> apiScopes = null, IEnumerable<string> tokenScopes = null) | ||
: base(EventCategories.Token, | ||
"Token Introspection Failure", | ||
EventTypes.Failure, | ||
EventIds.TokenIntrospectionFailure, | ||
errorMessage) | ||
{ | ||
ApiName = apiName; | ||
|
||
if (token.IsPresent()) | ||
{ | ||
Token = Obfuscate(token); | ||
} | ||
|
||
if (apiScopes != null) | ||
{ | ||
ApiScopes = apiScopes; | ||
} | ||
|
||
if (tokenScopes != null) | ||
{ | ||
TokenScopes = tokenScopes; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the API. | ||
/// </summary> | ||
/// <value> | ||
/// The name of the API. | ||
/// </value> | ||
public string ApiName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the token. | ||
/// </summary> | ||
/// <value> | ||
/// The token. | ||
/// </value> | ||
public string Token { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the API scopes. | ||
/// </summary> | ||
/// <value> | ||
/// The API scopes. | ||
/// </value> | ||
public IEnumerable<string> ApiScopes { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the token scopes. | ||
/// </summary> | ||
/// <value> | ||
/// The token scopes. | ||
/// </value> | ||
public IEnumerable<string> TokenScopes { get; set; } | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/IdentityServer4/Events/TokenIntrospectionSuccessEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using IdentityServer4.Extensions; | ||
using IdentityServer4.Validation; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace IdentityServer4.Events | ||
{ | ||
/// <summary> | ||
/// Event for successful token introspection | ||
/// </summary> | ||
/// <seealso cref="IdentityServer4.Events.Event" /> | ||
public class TokenIntrospectionSuccessEvent : Event | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TokenIntrospectionSuccessEvent" /> class. | ||
/// </summary> | ||
/// <param name="result">The result.</param> | ||
public TokenIntrospectionSuccessEvent(IntrospectionRequestValidationResult result) | ||
: base(EventCategories.Token, | ||
"Token Introspection Success", | ||
EventTypes.Success, | ||
EventIds.TokenIntrospectionSuccess) | ||
{ | ||
ApiName = result.Api.Name; | ||
IsActive = result.IsActive; | ||
|
||
if (result.Token.IsPresent()) | ||
{ | ||
Token = Obfuscate(result.Token); | ||
} | ||
|
||
if (!result.Claims.IsNullOrEmpty()) | ||
{ | ||
ClaimTypes = result.Claims.Select(c => c.Type).Distinct(); | ||
TokenScopes = result.Claims.Where(c => c.Type == "scope").Select(c => c.Value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the API. | ||
/// </summary> | ||
/// <value> | ||
/// The name of the API. | ||
/// </value> | ||
public string ApiName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether this instance is active. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if this instance is active; otherwise, <c>false</c>. | ||
/// </value> | ||
public bool IsActive { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the token. | ||
/// </summary> | ||
/// <value> | ||
/// The token. | ||
/// </value> | ||
public string Token { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the claim types. | ||
/// </summary> | ||
/// <value> | ||
/// The claim types. | ||
/// </value> | ||
public IEnumerable<string> ClaimTypes { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the token scopes. | ||
/// </summary> | ||
/// <value> | ||
/// The token scopes. | ||
/// </value> | ||
public IEnumerable<string> TokenScopes { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters