All checks were successful
Build, Push and Run Container / build (push) Successful in 25s
Updates the Tesla OIDC address to use the production environment. This ensures that the application uses the correct endpoint for authentication and avoids issues related to using the development environment in production.
53 lines
2.2 KiB
C#
53 lines
2.2 KiB
C#
using System.Collections.Concurrent;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using Microsoft.IdentityModel.Protocols;
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
namespace ProofOfConcept.Utilities;
|
|
|
|
using Microsoft.IdentityModel.Protocols;
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
|
|
public sealed class TeslaOIDCConfigurationManager : IConfigurationManager<OpenIdConnectConfiguration>
|
|
{
|
|
private readonly IConfigurationManager<OpenIdConnectConfiguration> _inner;
|
|
|
|
public TeslaOIDCConfigurationManager(string metadataAddress)
|
|
{
|
|
_inner = new ConfigurationManager<OpenIdConnectConfiguration>(metadataAddress, new OpenIdConnectConfigurationRetriever(), new HttpDocumentRetriever());
|
|
}
|
|
|
|
public async Task<OpenIdConnectConfiguration> GetConfigurationAsync(CancellationToken cancel)
|
|
{
|
|
OpenIdConnectConfiguration? configuration = await _inner.GetConfigurationAsync(cancel);
|
|
|
|
string cloudEndpointBase = "https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3";
|
|
configuration.AuthorizationEndpoint = $"{cloudEndpointBase}/authorize";
|
|
configuration.TokenEndpoint = $"{cloudEndpointBase}/token";
|
|
configuration.JwksUri = $"{cloudEndpointBase}/discovery/thirdparty/keys";
|
|
configuration.EndSessionEndpoint = $"{cloudEndpointBase}/logout";
|
|
configuration.UserInfoEndpoint = $"{cloudEndpointBase}/userinfo";
|
|
|
|
return configuration;
|
|
}
|
|
|
|
public void RequestRefresh() => _inner.RequestRefresh();
|
|
}
|
|
|
|
public class TeslaDocumentRetriever : IDocumentRetriever
|
|
{
|
|
private readonly HttpDocumentRetriever httpDocumentRetriever;
|
|
|
|
public TeslaDocumentRetriever(HttpDocumentRetriever httpDocumentRetriever)
|
|
{
|
|
this.httpDocumentRetriever = httpDocumentRetriever;
|
|
}
|
|
|
|
public async Task<string> GetDocumentAsync(string address, CancellationToken cancel)
|
|
{
|
|
address = address.Replace("https://fleet-auth.tesla.com/oauth2/v3", "https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3");
|
|
string document = await this.httpDocumentRetriever.GetDocumentAsync(address, cancel);
|
|
return document.Replace("https://fleet-auth.tesla.com/oauth2/v3", "https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3");
|
|
}
|
|
} |