matreurai
matreurai

Reputation: 191

How to validate Azure Credentials Format (ClientID, ClientSecret, TenantID)

I've been trying to find in Microsoft documentation (learn.microsoft.com) format specifications for the ClientID, the ClientSecret and the TenantID in order to connect to SharePoint REST API v1.

I am simply trying to validate format with regex in C# for each of them. I would have expect Microsoft to provide at least an explanation for those in the documentation, but can't manage to find anything about it.

I don't need a specific regex for each or code examples, I simply need the format specifications.

As an example, something like :

CliendID : alphanumerical string of 12 characters separated by dashes -> xyz-xyz-yzx-xyz
CliendSecret : ...
TenantID : ...

Found this ticket online, but still inconclusive : https://learn.microsoft.com/en-us/answers/questions/263677/validating-client-and-tenant-id-using-regular-expr

Thanks a lot

Upvotes: 1

Views: 1031

Answers (2)

Jeremy Bradshaw
Jeremy Bradshaw

Reputation: 119

For TenantId / ApplicationId and Certificate validation, here's what I'm doing in PowerShell functions/scripts:

[Parameter(Mandatory = $true)]
[ValidateScript({ if (([guid]::TryParse($_, [ref]([guid]::NewGuid()))) -or ($_ -like '*.onmicrosoft.com')) { $true } else { throw "Invalid TenantId: $($_)" } })]
[Object]$TenantId,

[Parameter(Mandatory = $true)]
[ValidateScript({ if ([guid]::TryParse($_, [ref]([guid]::NewGuid()))) { $true } else { throw "Invalid ApplicationId: $($_)" } })]
[Object]$ApplicationId,

[Parameter(Mandatory = $true, ParameterSetName = 'Certificate')]
[X509Certificate]$Certificate,

My reason for having shown up today was that I'm looking for regex to validate Client Secrets. I know it's not important, but sometimes our OCD says screw that and lets get this thing figured out. Don't want to rely on the MSAL libraries all the time. After all, I survived a long time on MSGraphPSEssentials.

Here are two links which I think might give you some of what you were asking about:

Upvotes: -1

Zain
Zain

Reputation: 1252

This is a very niche thing that 99.99% of people don't need to do, which is why it's not in the learn.microsoft.com documentation. I presume this would be useful only in CI/CD pipelines. You can use regex builders, but I think the likely situation is that this is unnecessary; if you are building a CI/CD pipeline, it should either work or fail outright; it shouldn't give you malformed information. I appreciate this might not be the answer you're looking for, but I recommend reconsidering if this is a good use of your time.

Upvotes: -2

Related Questions