Skip to content

validate access token#17566

Closed
ZhuXiaoBing-cn wants to merge 13 commits intoAzure:masterfrom
ZhuXiaoBing-cn:validate_access_token
Closed

validate access token#17566
ZhuXiaoBing-cn wants to merge 13 commits intoAzure:masterfrom
ZhuXiaoBing-cn:validate_access_token

Conversation

@ZhuXiaoBing-cn
Copy link
Contributor

  • add resource server autoconfiguration
  • add audience validator
  • add tenant validator
  • add issuer validator

  * add resource server autoconfiguration
  * add audience validator
  * add tenant validator
  * add issuer validator
@ghost ghost added the azure-spring All azure-spring related issues label Nov 13, 2020
@saragluna saragluna added the azure-spring-aad Spring active directory related issues. label Nov 13, 2020
@EnableConfigurationProperties(AADAuthenticationProperties.class)
@ConditionalOnClass(name = {"org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"})
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnProperty(prefix = "azure.activedirectory", value = {"client-id", "client-secret", "tenant-id"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these properties?

@ConditionalOnMissingBean(JwtDecoder.class)
JwtDecoder jwtDecoderByJwkKeySetUri() {
IdentityEndpoints endpoints = new IdentityEndpoints(aadAuthenticationProperties.getUri());
NimbusJwtDecoder nimbusJwtDecoder = NimbusJwtDecoder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why the tenant id is required here, but why this prefix azure.activedirectory.resource is used here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for the case of single-tenant app, the tenant id will be its tenant id. For multi-tenant app, it will be common?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about azure.activedirectory.resource ,a hand by mistake,it will be modified.
So for the case of single-tenant app, the tenant id will be its tenant id. For multi-tenant app, it will be common?
yes

private AADAuthenticationProperties aadAuthenticationProperties;

@Bean
@ConditionalOnProperty(prefix = "azure.activedirectory.resource", value = {"client-id", "tenant-id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these properties are not required right?

If tenant id is provided, we will construct the jwkset uri from the tenant id, otherwise we could use common?
If no client-id or app-id-uri is provided, we could skip the audience check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these properties are not required right?
yes.

If tenant id is provided, we will construct the jwkset uri from the tenant id, otherwise we could use common?
If no client-id or app-id-uri is provided, we could skip the audience check?

Yes, you are right.

List<String> validAudiences = new ArrayList<>();
validAudiences.add(aadAuthenticationProperties.getClientId());
validAudiences.add(aadAuthenticationProperties.getAppIdUri());
validators.add(new AzureJwtIssuerValidator(aadAuthenticationProperties.getTenantId(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using tenant ids to construct the issuer validator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the issuer in the form of "https://sts.windows.net/4acebda4-c077-434a-8675-c4b5afebc8da/", so I hope that by passing tenantId to construct corresponding issuer, then the access token of the 'iss' of claims to match.


private List<String> assembleIssuer(String tenantId) {
List<String> issuers = new ArrayList<>();
issuers.add(LOGIN_MICROSOFT_ONLINE_ISSUER + tenantId + "/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check the tenant in issuer claim in this validator? Which doc are we following here?

private final JwtClaimValidator<String> validator;

public AzureJwtTenantValidator(String tenantId, Set<String> allowedTenantids) {
Assert.notNull(tenantId, "tenantId cannot be null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need both to be non-null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,It will be modified.

paolamvhz and others added 10 commits November 13, 2020 12:59
…earch to PhoneNumberReservation (Azure#17253)

* Renaming from PhoneNumberSearch to PhoneNumberReservation

* Renaming from PhoneNumberSearch to PhoneNumberReservation

* Renaming from PhoneNumberSearch to PhoneNumberReservation

* upadating readme samples

* Renaming the model CreateSearchReponse and CreateSearchOptions

* Fixing tests

* Fixing tests

* fixing typo un reservations
…e#17565)

* Add AppConfig and Event Hubs samples for using exporters

* Fix compiler warnings

* Update sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/pom.xml

* Update method names
* Improve Update-ChangeLog Logic

* Updates to ChangeLog-Operations.ps1, copy-docs-to-blobstorage.ps1, Invoke-GitHubAPI.ps1 and Package-Properties.ps1

* More changeLog Logic Improvements

* Update date parsing

Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
… public to private (Azure#17576)

* changing some public methods

* updating Reade file

* Fixing Readme
* [Service Bus] Remove viaPartitionKey

* Remove unused imports
…be performed

 * tenantId is null, the default assignment is 'common'
 * The properties of AzureResourceServerAutoConfiguration made changes
@jialindai
Copy link
Contributor

What will be the configuration file looks like?

@jialindai
Copy link
Contributor

We also need unit tests.

* add unit tests
* pom file add resource-server dependencies
* spring.factories file add autoconfiguration
@ZhuXiaoBing-cn
Copy link
Contributor Author

ZhuXiaoBing-cn commented Nov 17, 2020

@jialindai

  • What will be the configuration file looks like?

configuration file looks like:
In the case of a single tenant, our application.properties:

azure.activedirectory.tenant-id=4acebda4-xxxxxx-c4b5afebc
azure.activedirectory.client-id=f6fae4ff-xxxxxx-ccb0a2ee2
azure.activedirectory.app-id-uri=api://f6fae4ff-xxxxxx-ccb0a2ee2

Configuration above, we will verify aud,iss,tid,nbf,exp.
When our azure.activedirectory.client-id and azure.activedirectory.app-id-uri are not configured, we will not validate the aud.when our azure.activedirectory.tenant-id are not configured,it will be given a default common,and we will skip tid and iss.For nbf,exp,it is validated by default.

In the case of a multi-tenant, our application.properties:

azure.activedirectory.tenant-id=common
azure.activedirectory.client-id=f6fae4ff-xxxxxx-ccb0a2ee2e2c
azure.activedirectory.app-id-uri=api://f6fae4ff-xxxxxx-ccb0a2ee2e2c
azure.activedirectory.allowed-tenant-ids=4acebda4-xxxxxx-c4b58da,3aef70d5-xxxxxx-22e8a91,308e3453-xxxxxx-28a8fb5e

Under multi-tenant the azure.activedirectory.tenant-id will be configured as common and if it is not configured he will use common by default.For azure.activedirectory.allowed-tenant-ids, the configuration will be available to those tenants.When it is configured, we will validate tid, iss, otherwise we will not validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-spring All azure-spring related issues azure-spring-aad Spring active directory related issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants