Skip to content

Commit

Permalink
Use AuthorizeRequestType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersAbel committed Nov 14, 2023
1 parent f73a0a0 commit 9d23c2c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/IdentityServer/Endpoints/AuthorizeEndpointBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private Task RaiseFailureEventAsync(ValidatedAuthorizeRequest request, string er
Telemetry.Metrics.TokenIssuedFailure(
request.ClientId,
request.GrantType,
request.IsPushedAuthorizationRequest,
request.AuthorizeRequestType,
error);
return _events.RaiseAsync(new TokenIssuedFailureEvent(request, error, errorDescription));
}
Expand All @@ -241,7 +241,7 @@ private Task RaiseResponseEventAsync(AuthorizeResponse response)
Telemetry.Metrics.TokenIssued(
response.Request.ClientId,
response.Request.GrantType,
response.Request.IsPushedAuthorizationRequest);
response.Request.AuthorizeRequestType);
return _events.RaiseAsync(new TokenIssuedSuccessEvent(response));
}

Expand Down
8 changes: 4 additions & 4 deletions src/IdentityServer/Endpoints/TokenEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task<IEndpointResult> ProcessTokenRequestAsync(HttpContext context
if (clientResult.IsError)
{
var errorMsg = clientResult.Error ?? OidcConstants.TokenErrors.InvalidClient;
Telemetry.Metrics.TokenIssuedFailure(clientResult.Client?.ClientId, null, false, errorMsg);
Telemetry.Metrics.TokenIssuedFailure(clientResult.Client?.ClientId, null, null, errorMsg);
return Error(errorMsg);
}

Expand All @@ -113,7 +113,7 @@ private async Task<IEndpointResult> ProcessTokenRequestAsync(HttpContext context
var error = await TryReadProofTokens(context, requestContext);
if (error != null)
{
Telemetry.Metrics.TokenIssuedFailure(clientResult.Client.ClientId, null, false, error.Response.Error);
Telemetry.Metrics.TokenIssuedFailure(clientResult.Client.ClientId, null, null, error.Response.Error);
return error;
}

Expand All @@ -122,7 +122,7 @@ private async Task<IEndpointResult> ProcessTokenRequestAsync(HttpContext context
{
await _events.RaiseAsync(new TokenIssuedFailureEvent(requestResult));
Telemetry.Metrics.TokenIssuedFailure(
clientResult.Client.ClientId, requestResult.ValidatedRequest?.GrantType, false, requestResult.Error);
clientResult.Client.ClientId, requestResult.ValidatedRequest?.GrantType, null, requestResult.Error);
var err = Error(requestResult.Error, requestResult.ErrorDescription, requestResult.CustomResponse);
err.Response.DPoPNonce = requestResult.DPoPNonce;
return err;
Expand All @@ -133,7 +133,7 @@ private async Task<IEndpointResult> ProcessTokenRequestAsync(HttpContext context
var response = await _responseGenerator.ProcessAsync(requestResult);

await _events.RaiseAsync(new TokenIssuedSuccessEvent(response, requestResult));
Telemetry.Metrics.TokenIssued(clientResult.Client.ClientId, requestResult.ValidatedRequest.GrantType, false);
Telemetry.Metrics.TokenIssued(clientResult.Client.ClientId, requestResult.ValidatedRequest.GrantType, null);
LogTokens(response, requestResult);

// return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ public class ValidatedAuthorizeRequest : ValidatedRequest
/// </summary>
public string? PushedAuthorizationReferenceValue { get; set; }

/// <summary>
/// Is this a pushed authorization request?
/// </summary>
public bool IsPushedAuthorizationRequest { get => PushedAuthorizationReferenceValue.IsPresent(); }

/// <summary>
/// Gets or sets a value indicating the context in which authorization
/// validation is occurring (the PAR endpoint or the authorize endpoint with
Expand Down
17 changes: 9 additions & 8 deletions src/Telemetry/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE in the project root for license information.


using Duende.IdentityServer.Validation;
using System;
using System.Diagnostics;
using System.Diagnostics.Metrics;
Expand Down Expand Up @@ -217,9 +218,9 @@ public static class Tags
public const string Path = "path";

/// <summary>
/// pushed_authorization_request
/// authorize_request_type
/// </summary>
public const string PushedAuthorizationRequest = "pushed_authorization_request";
public const string AuthorizeRequestType = "authorize_request_type";

/// <summary>
/// scheme
Expand Down Expand Up @@ -646,14 +647,14 @@ public static void RevocationFailure(string clientId, string error)
/// </summary>
/// <param name="clientId">Client Id</param>
/// <param name="grantType">Grant Type</param>
/// <param name="isPushedAuthorizationRequest">Is this a result of a pushed authorization request?</param>
public static void TokenIssued(string clientId, string grantType, bool isPushedAuthorizationRequest)
/// <param name="requestType">Type of authorization request</param>
public static void TokenIssued(string clientId, string grantType, AuthorizeRequestType? requestType)
{
Success(clientId);
TokenIssuedCounter.Add(1,
new(Tags.Client, clientId),
new(Tags.GrantType, grantType),
new(Tags.PushedAuthorizationRequest, isPushedAuthorizationRequest));
new(Tags.AuthorizeRequestType, requestType));
}

/// <summary>
Expand All @@ -667,14 +668,14 @@ public static void TokenIssued(string clientId, string grantType, bool isPushedA
/// <param name="clientId">Client Id</param>
/// <param name="grantType">Grant Type</param>
/// <param name="error">Error</param>
/// <param name="isPushedAuthorizationRequest">Is this a result of a pushed authorization request?</param>
public static void TokenIssuedFailure(string clientId, string grantType, bool isPushedAuthorizationRequest, string error)
/// <param name="requestType">Type of authorization request</param>
public static void TokenIssuedFailure(string clientId, string grantType, AuthorizeRequestType? requestType, string error)
{
Failure(error, clientId);
TokenIssuedFailureCounter.Add(1,
new(Tags.Client, clientId),
new(Tags.GrantType, grantType),
new(Tags.PushedAuthorizationRequest, isPushedAuthorizationRequest),
new(Tags.AuthorizeRequestType, requestType),
new(Tags.Error, error));
}

Expand Down

0 comments on commit 9d23c2c

Please sign in to comment.