diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 995c5ca..a65de39 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -18,8 +18,8 @@ jobs: with: dotnet-version: '8.0' include-prerelease: True - - name: Build AngularAzureADMultipleApis - run: dotnet build ./AngularAzureADMultipleApis/ApiWithMutlipleApis.sln + - name: Build AngularMicrsoftEntraIDMultipleApis + run: dotnet build ./AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis.sln - name: Build BlazorWithApis run: dotnet build ./BlazorWithApis/BlazorApis.sln - name: Build ConfidentialClientCredentialsCertificate diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.browserslistrc b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.browserslistrc similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.browserslistrc rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.browserslistrc diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.editorconfig b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.editorconfig similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.editorconfig rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.editorconfig diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.gitignore b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.gitignore similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.gitignore rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.gitignore diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/extensions.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/extensions.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/extensions.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/extensions.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/launch.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/launch.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/launch.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/launch.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/tasks.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/tasks.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/.vscode/tasks.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/.vscode/tasks.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/README.md b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/README.md similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/README.md rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/README.md diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/angular.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/angular.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/angular.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/angular.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.key b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.key similarity index 98% rename from AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.key rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.key index 34525b8..cc4f625 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.key +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.key @@ -1,13 +1,13 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQCs7HI0KWqXEjH1fxXdkgVHg+1UgbtBhwkeZ3WhBsTGcwlqGUmzqlhKiR2hTd9G -dMhQm1tFeU9qAMpmglxR+XgoZoEv9uoXw/TeegdKvn1V3exTxeULIDGJOXK6wQ1M+4FLMr7zBWlM -hWmqcbYTHHVwwYd+ycDRHU3NAIxDfMUSQQIDAQABAoGAIB8z/7iJ0lJQ8XeQCj6ruGMrXP1UWZHK -AdnaIfVt7CdGYm0cIcHM8NuTo3khtqbO5xpU1Az60YggEPa6S4f558kGBIg4PQVxgE/Kv77ptGAk -rZG9FaCyIibGMh5aJLtxG0Fh1FGnuK1Xk1BKXtaGRUkZpKGg4rMJ9w3qp/T5vLkCQQDe+FiMqY2s -pxHEz+h3NJ0H2T81FCx2upf1fjTVtlQnJ7Gds6eZT0zwa3z1bSw+VkxICERY8C43bzPUJUgPIyLX -AkEAxooyVkJHmxlcIvZfrZPvQs+2GOXpWVnyjNUWf8t9G2MsmkdGIkp7oJhi5obpdNR+3jQe0xyr -Dvy1hbHuGp5opwJBALO6Zc5EogGozgbiPBVSoL2B3ZRQhaLSt8jYCYi3JtBFC8P927wVkwQ88IX4 -kXBSKbzqhQVX3Tkr9xArWRFylhMCQFmigt9WxSVM6cAPI1smctrjE/9hrVxds5fJjILdx/nZaIWu -sAdDQVVb9yrEthm85hpDxbbiNohppzpY/nqeEfkCQQDInS/pP5dYTUxFV+/YweK+6smN2v+dYZAi -5KShWRl5fwpl+mdJT3aziRb/kfYkhGPQMO06OnGzjNKt7Rg0Z8mD ------END RSA PRIVATE KEY----- +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQCs7HI0KWqXEjH1fxXdkgVHg+1UgbtBhwkeZ3WhBsTGcwlqGUmzqlhKiR2hTd9G +dMhQm1tFeU9qAMpmglxR+XgoZoEv9uoXw/TeegdKvn1V3exTxeULIDGJOXK6wQ1M+4FLMr7zBWlM +hWmqcbYTHHVwwYd+ycDRHU3NAIxDfMUSQQIDAQABAoGAIB8z/7iJ0lJQ8XeQCj6ruGMrXP1UWZHK +AdnaIfVt7CdGYm0cIcHM8NuTo3khtqbO5xpU1Az60YggEPa6S4f558kGBIg4PQVxgE/Kv77ptGAk +rZG9FaCyIibGMh5aJLtxG0Fh1FGnuK1Xk1BKXtaGRUkZpKGg4rMJ9w3qp/T5vLkCQQDe+FiMqY2s +pxHEz+h3NJ0H2T81FCx2upf1fjTVtlQnJ7Gds6eZT0zwa3z1bSw+VkxICERY8C43bzPUJUgPIyLX +AkEAxooyVkJHmxlcIvZfrZPvQs+2GOXpWVnyjNUWf8t9G2MsmkdGIkp7oJhi5obpdNR+3jQe0xyr +Dvy1hbHuGp5opwJBALO6Zc5EogGozgbiPBVSoL2B3ZRQhaLSt8jYCYi3JtBFC8P927wVkwQ88IX4 +kXBSKbzqhQVX3Tkr9xArWRFylhMCQFmigt9WxSVM6cAPI1smctrjE/9hrVxds5fJjILdx/nZaIWu +sAdDQVVb9yrEthm85hpDxbbiNohppzpY/nqeEfkCQQDInS/pP5dYTUxFV+/YweK+6smN2v+dYZAi +5KShWRl5fwpl+mdJT3aziRb/kfYkhGPQMO06OnGzjNKt7Rg0Z8mD +-----END RSA PRIVATE KEY----- diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.pem b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.pem similarity index 98% rename from AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.pem rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.pem index 585fc9a..f2247c7 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.pem +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.pem @@ -1,13 +1,13 @@ ------BEGIN CERTIFICATE----- -MIICQDCCAamgAwIBAgIJAIKGapdMCt4NMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMTCWxvY2Fs -aG9zdDAeFw0yMDAyMjAyMjU3MjFaFw0zMDAyMjEyMjU3MjFaMBQxEjAQBgNVBAMTCWxvY2FsaG9z -dDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArOxyNClqlxIx9X8V3ZIFR4PtVIG7QYcJHmd1 -oQbExnMJahlJs6pYSokdoU3fRnTIUJtbRXlPagDKZoJcUfl4KGaBL/bqF8P03noHSr59Vd3sU8Xl -CyAxiTlyusENTPuBSzK+8wVpTIVpqnG2Exx1cMGHfsnA0R1NzQCMQ3zFEkECAwEAAaOBmTCBljAS -BgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIB/jAUBgNVHREEDTALgglsb2NhbGhvc3Qw -OwYDVR0lBDQwMgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAwYIKwYBBQUHAwQGCCsGAQUF -BwMIMB0GA1UdDgQWBBQaVighscgq5k8BjEzeSsZp+6RxITANBgkqhkiG9w0BAQsFAAOBgQBXH/Sq -jekwz+O0eG0zA2MA2LSwt7OELi54vATFYkXO45IO5frRagUTWDkx85/Vfm9OcdfoaHD1UzPkGBU0 -BPsnN3SGCB3Pk5jSRaXIBBiqByDFiP+G6EYmUYhLxB3FpJp6S5KlnQtdtLkl3KuT8KBtc9haro+e -lDlUx5s/FM3SJw== ------END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICQDCCAamgAwIBAgIJAIKGapdMCt4NMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMTCWxvY2Fs +aG9zdDAeFw0yMDAyMjAyMjU3MjFaFw0zMDAyMjEyMjU3MjFaMBQxEjAQBgNVBAMTCWxvY2FsaG9z +dDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArOxyNClqlxIx9X8V3ZIFR4PtVIG7QYcJHmd1 +oQbExnMJahlJs6pYSokdoU3fRnTIUJtbRXlPagDKZoJcUfl4KGaBL/bqF8P03noHSr59Vd3sU8Xl +CyAxiTlyusENTPuBSzK+8wVpTIVpqnG2Exx1cMGHfsnA0R1NzQCMQ3zFEkECAwEAAaOBmTCBljAS +BgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIB/jAUBgNVHREEDTALgglsb2NhbGhvc3Qw +OwYDVR0lBDQwMgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAwYIKwYBBQUHAwQGCCsGAQUF +BwMIMB0GA1UdDgQWBBQaVighscgq5k8BjEzeSsZp+6RxITANBgkqhkiG9w0BAQsFAAOBgQBXH/Sq +jekwz+O0eG0zA2MA2LSwt7OELi54vATFYkXO45IO5frRagUTWDkx85/Vfm9OcdfoaHD1UzPkGBU0 +BPsnN3SGCB3Pk5jSRaXIBBiqByDFiP+G6EYmUYhLxB3FpJp6S5KlnQtdtLkl3KuT8KBtc9haro+e +lDlUx5s/FM3SJw== +-----END CERTIFICATE----- diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.pfx b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.pfx similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/certs/dev_localhost.pfx rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/certs/dev_localhost.pfx diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/karma.conf.js b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/karma.conf.js similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/karma.conf.js rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/karma.conf.js diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/package-lock.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/package-lock.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/package-lock.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/package-lock.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/package.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/package.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/package.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/package.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app-routing.module.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app-routing.module.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app-routing.module.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app-routing.module.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.html similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.html diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.spec.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.spec.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.spec.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.spec.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.ts index 28ae256..5ea1efb 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.component.ts @@ -1,18 +1,18 @@ -import { Component, OnInit } from '@angular/core'; -import { AuthService } from './auth.service'; - -@Component({ - selector: 'app-root', - templateUrl: 'app.component.html', -}) -export class AppComponent implements OnInit { - constructor(public authService: AuthService) {} - - ngOnInit() { - this.authService - .checkAuth() - .subscribe((isAuthenticated) => - console.log('app authenticated', isAuthenticated) - ); - } -} +import { Component, OnInit } from '@angular/core'; +import { AuthService } from './auth.service'; + +@Component({ + selector: 'app-root', + templateUrl: 'app.component.html', +}) +export class AppComponent implements OnInit { + constructor(public authService: AuthService) {} + + ngOnInit() { + this.authService + .checkAuth() + .subscribe((isAuthenticated) => + console.log('app authenticated', isAuthenticated) + ); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.module.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.module.ts similarity index 97% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.module.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.module.ts index 25c77e8..c9f54de 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/app.module.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/app.module.ts @@ -1,67 +1,67 @@ -import { DirectApiCallComponent } from './directApiCall/directApiCall.component'; -import { APP_INITIALIZER, NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { RouterModule } from '@angular/router'; -import { AuthModule, OidcConfigService, LogLevel } from 'angular-auth-oidc-client'; -import { AppComponent } from './app.component'; -import { HomeComponent } from './home/home.component'; -import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; -import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; -import { AuthInterceptor } from './auth.interceptor'; -import { NavMenuComponent } from './nav-menu/nav-menu.component'; -import { GraphApiCallComponent } from './graphApiCall/graphApiCall.component'; -import { ApplicationApiCallComponent } from './applicationApiCall/applicationApiCall.component'; -import { DelegatedApiCallComponent } from './delegatedApiCall/delegatedApiCall.component'; -import { AuthorizationGuard } from './authorization.guard'; - -@NgModule({ - declarations: [ - AppComponent, - HomeComponent, - NavMenuComponent, - UnauthorizedComponent, - DirectApiCallComponent, - GraphApiCallComponent, - ApplicationApiCallComponent, - DelegatedApiCallComponent - ], - imports: [ - BrowserModule, - RouterModule.forRoot([ - { path: '', redirectTo: 'home', pathMatch: 'full' }, - { path: 'home', component: HomeComponent }, - { path: 'directApiCall', component: DirectApiCallComponent, canActivate: [AuthorizationGuard] }, - { path: 'graphApiCall', component: GraphApiCallComponent, canActivate: [AuthorizationGuard] }, - { path: 'applicationApiCall', component: ApplicationApiCallComponent, canActivate: [AuthorizationGuard] }, - { path: 'delegatedApiCall', component: DelegatedApiCallComponent, canActivate: [AuthorizationGuard] }, - { path: 'unauthorized', component: UnauthorizedComponent }, - ], { relativeLinkResolution: 'legacy' }), - AuthModule.forRoot({ - config: { - authority: 'https://login.microsoftonline.com/7ff95b15-dc21-4ba6-bc92-824856578fc1/v2.0', - authWellknownEndpointUrl: 'https://login.microsoftonline.com/7ff95b15-dc21-4ba6-bc92-824856578fc1/v2.0', - redirectUrl: window.location.origin, - clientId: 'ad6b0351-92b4-4ee9-ac8d-3e76e5fd1c67', - scope: 'openid profile email api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user offline_access', - responseType: 'code', - silentRenew: true, - useRefreshToken: true, - maxIdTokenIatOffsetAllowedInSeconds: 600, - issValidationOff: false, - autoUserInfo: false, - logLevel: LogLevel.Debug - }, - }), - HttpClientModule, - ], - providers: [ - { - provide: HTTP_INTERCEPTORS, - useClass: AuthInterceptor, - multi: true, - }, - AuthorizationGuard - ], - bootstrap: [AppComponent], -}) -export class AppModule {} +import { DirectApiCallComponent } from './directApiCall/directApiCall.component'; +import { APP_INITIALIZER, NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { RouterModule } from '@angular/router'; +import { AuthModule, OidcConfigService, LogLevel } from 'angular-auth-oidc-client'; +import { AppComponent } from './app.component'; +import { HomeComponent } from './home/home.component'; +import { UnauthorizedComponent } from './unauthorized/unauthorized.component'; +import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { AuthInterceptor } from './auth.interceptor'; +import { NavMenuComponent } from './nav-menu/nav-menu.component'; +import { GraphApiCallComponent } from './graphApiCall/graphApiCall.component'; +import { ApplicationApiCallComponent } from './applicationApiCall/applicationApiCall.component'; +import { DelegatedApiCallComponent } from './delegatedApiCall/delegatedApiCall.component'; +import { AuthorizationGuard } from './authorization.guard'; + +@NgModule({ + declarations: [ + AppComponent, + HomeComponent, + NavMenuComponent, + UnauthorizedComponent, + DirectApiCallComponent, + GraphApiCallComponent, + ApplicationApiCallComponent, + DelegatedApiCallComponent + ], + imports: [ + BrowserModule, + RouterModule.forRoot([ + { path: '', redirectTo: 'home', pathMatch: 'full' }, + { path: 'home', component: HomeComponent }, + { path: 'directApiCall', component: DirectApiCallComponent, canActivate: [AuthorizationGuard] }, + { path: 'graphApiCall', component: GraphApiCallComponent, canActivate: [AuthorizationGuard] }, + { path: 'applicationApiCall', component: ApplicationApiCallComponent, canActivate: [AuthorizationGuard] }, + { path: 'delegatedApiCall', component: DelegatedApiCallComponent, canActivate: [AuthorizationGuard] }, + { path: 'unauthorized', component: UnauthorizedComponent }, + ], { relativeLinkResolution: 'legacy' }), + AuthModule.forRoot({ + config: { + authority: 'https://login.microsoftonline.com/7ff95b15-dc21-4ba6-bc92-824856578fc1/v2.0', + authWellknownEndpointUrl: 'https://login.microsoftonline.com/7ff95b15-dc21-4ba6-bc92-824856578fc1/v2.0', + redirectUrl: window.location.origin, + clientId: 'ad6b0351-92b4-4ee9-ac8d-3e76e5fd1c67', + scope: 'openid profile email api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user offline_access', + responseType: 'code', + silentRenew: true, + useRefreshToken: true, + maxIdTokenIatOffsetAllowedInSeconds: 600, + issValidationOff: false, + autoUserInfo: false, + logLevel: LogLevel.Debug + }, + }), + HttpClientModule, + ], + providers: [ + { + provide: HTTP_INTERCEPTORS, + useClass: AuthInterceptor, + multi: true, + }, + AuthorizationGuard + ], + bootstrap: [AppComponent], +}) +export class AppModule {} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.html similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.html index d49af2b..38fa4ef 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.html @@ -1,25 +1,25 @@ - - - -
- - - -

- - Is Authenticated: {{ isAuthenticated.isAuthenticated }} - -

- -
-
Data from API using an Application API
-
-
{{ dataFromAzureProtectedApi$ | async | json }}
-
-
- -
- + + + +
+ + + +

+ + Is Authenticated: {{ isAuthenticated.isAuthenticated }} + +

+ +
+
Data from API using an Application API
+
+
{{ dataFromAzureProtectedApi$ | async | json }}
+
+
+ +
+ diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.ts similarity index 97% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.ts index 6cd44b2..48d88f1 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/applicationApiCall/applicationApiCall.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/applicationApiCall/applicationApiCall.component.ts @@ -1,32 +1,32 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { finalize } from 'rxjs/operators'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-application-api-call', - templateUrl: 'applicationApiCall.component.html', -}) -export class ApplicationApiCallComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated$: Observable; - httpRequestRunning = false; - constructor( - private authService: AuthService, - private httpClient: HttpClient - ) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.isAuthenticated$ = this.authService.signedIn$; - } - callApi() { - this.httpRequestRunning = true; - this.dataFromAzureProtectedApi$ = this.httpClient - .get('https://localhost:44390/ServiceApiCalls') - .pipe(finalize(() => (this.httpRequestRunning = false))); - } -} +import { HttpClient } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { finalize } from 'rxjs/operators'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-application-api-call', + templateUrl: 'applicationApiCall.component.html', +}) +export class ApplicationApiCallComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated$: Observable; + httpRequestRunning = false; + constructor( + private authService: AuthService, + private httpClient: HttpClient + ) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.isAuthenticated$ = this.authService.signedIn$; + } + callApi() { + this.httpRequestRunning = true; + this.dataFromAzureProtectedApi$ = this.httpClient + .get('https://localhost:44390/ServiceApiCalls') + .pipe(finalize(() => (this.httpRequestRunning = false))); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.interceptor.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.interceptor.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.interceptor.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.interceptor.ts index 00a7265..b2d2783 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.interceptor.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.interceptor.ts @@ -1,31 +1,31 @@ -import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { AuthService } from './auth.service'; - -@Injectable() -export class AuthInterceptor implements HttpInterceptor { - private secureRoutes = ['https://localhost:44390']; - - constructor(private authService: AuthService) {} - - intercept( - request: HttpRequest, - next: HttpHandler - ) { - if (!this.secureRoutes.find((x) => request.url.startsWith(x))) { - return next.handle(request); - } - - const token = this.authService.token; - - if (!token) { - return next.handle(request); - } - - request = request.clone({ - headers: request.headers.set('Authorization', 'Bearer ' + token), - }); - - return next.handle(request); - } -} +import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { AuthService } from './auth.service'; + +@Injectable() +export class AuthInterceptor implements HttpInterceptor { + private secureRoutes = ['https://localhost:44390']; + + constructor(private authService: AuthService) {} + + intercept( + request: HttpRequest, + next: HttpHandler + ) { + if (!this.secureRoutes.find((x) => request.url.startsWith(x))) { + return next.handle(request); + } + + const token = this.authService.token; + + if (!token) { + return next.handle(request); + } + + request = request.clone({ + headers: request.headers.set('Authorization', 'Bearer ' + token), + }); + + return next.handle(request); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.service.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.service.ts similarity index 95% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.service.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.service.ts index dfd2afc..86fb7a9 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/auth.service.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/auth.service.ts @@ -1,36 +1,36 @@ -import { Injectable } from '@angular/core'; -import { OidcSecurityService } from 'angular-auth-oidc-client'; -import { of } from 'rxjs'; - -@Injectable({ providedIn: 'root' }) -export class AuthService { - constructor(private oidcSecurityService: OidcSecurityService) {} - - get signedIn$() { - return this.oidcSecurityService.isAuthenticated$; - } - - get token() { - return this.oidcSecurityService.getAccessToken(); - } - - get userData$() { - return this.oidcSecurityService.userData$; - } - - checkAuth() { - return this.oidcSecurityService.checkAuth(); - } - - signIn() { - return of(this.oidcSecurityService.authorize()); - } - - signOut() { - this.oidcSecurityService.logoff(); - } - - forceRefreshSession() { - return this.oidcSecurityService.forceRefreshSession(); - } -} +import { Injectable } from '@angular/core'; +import { OidcSecurityService } from 'angular-auth-oidc-client'; +import { of } from 'rxjs'; + +@Injectable({ providedIn: 'root' }) +export class AuthService { + constructor(private oidcSecurityService: OidcSecurityService) {} + + get signedIn$() { + return this.oidcSecurityService.isAuthenticated$; + } + + get token() { + return this.oidcSecurityService.getAccessToken(); + } + + get userData$() { + return this.oidcSecurityService.userData$; + } + + checkAuth() { + return this.oidcSecurityService.checkAuth(); + } + + signIn() { + return of(this.oidcSecurityService.authorize()); + } + + signOut() { + this.oidcSecurityService.logoff(); + } + + forceRefreshSession() { + return this.oidcSecurityService.forceRefreshSession(); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/authorization.guard.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/authorization.guard.ts similarity index 97% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/authorization.guard.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/authorization.guard.ts index 6e7e85e..78cb92e 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/authorization.guard.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/authorization.guard.ts @@ -1,25 +1,25 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; -import { OidcSecurityService } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; - -@Injectable({ providedIn: 'root' }) -export class AuthorizationGuard implements CanActivate { - constructor(private oidcSecurityService: OidcSecurityService, private router: Router) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return this.oidcSecurityService.isAuthenticated$.pipe( - map(({ isAuthenticated }) => { - console.log('AuthorizationGuard, canActivate isAuthorized: ' + isAuthenticated); - - if (!isAuthenticated) { - this.router.navigate(['/unauthorized']); - return false; - } - - return true; - }) - ); - } -} +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; +import { OidcSecurityService } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +@Injectable({ providedIn: 'root' }) +export class AuthorizationGuard implements CanActivate { + constructor(private oidcSecurityService: OidcSecurityService, private router: Router) {} + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + return this.oidcSecurityService.isAuthenticated$.pipe( + map(({ isAuthenticated }) => { + console.log('AuthorizationGuard, canActivate isAuthorized: ' + isAuthenticated); + + if (!isAuthenticated) { + this.router.navigate(['/unauthorized']); + return false; + } + + return true; + }) + ); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.html similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.html index dd188a1..499d695 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.html @@ -1,25 +1,25 @@ - - - -
- - - -

- - Is Authenticated: {{ isAuthenticated.isAuthenticated }} - -

- -
-
Data from API using user delegated API
-
-
{{ dataFromAzureProtectedApi$ | async | json }}
-
-
- -
- + + + +
+ + + +

+ + Is Authenticated: {{ isAuthenticated.isAuthenticated }} + +

+ +
+
Data from API using user delegated API
+
+
{{ dataFromAzureProtectedApi$ | async | json }}
+
+
+ +
+ diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.ts similarity index 97% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.ts index 9d76523..71271d8 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/delegatedApiCall/delegatedApiCall.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/delegatedApiCall/delegatedApiCall.component.ts @@ -1,33 +1,33 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { finalize } from 'rxjs/operators'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-delegated-api-call', - templateUrl: 'delegatedApiCall.component.html', -}) -export class DelegatedApiCallComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated$: Observable; - httpRequestRunning = false; - constructor( - private authService: AuthService, - private httpClient: HttpClient - ) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.isAuthenticated$ = this.authService.signedIn$; - } - - callApi() { - this.httpRequestRunning = true; - this.dataFromAzureProtectedApi$ = this.httpClient - .get('https://localhost:44390/DelegatedUserApiCalls') - .pipe(finalize(() => (this.httpRequestRunning = false))); - } -} +import { HttpClient } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { finalize } from 'rxjs/operators'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-delegated-api-call', + templateUrl: 'delegatedApiCall.component.html', +}) +export class DelegatedApiCallComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated$: Observable; + httpRequestRunning = false; + constructor( + private authService: AuthService, + private httpClient: HttpClient + ) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.isAuthenticated$ = this.authService.signedIn$; + } + + callApi() { + this.httpRequestRunning = true; + this.dataFromAzureProtectedApi$ = this.httpClient + .get('https://localhost:44390/DelegatedUserApiCalls') + .pipe(finalize(() => (this.httpRequestRunning = false))); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.html similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.html index 1b3c3a8..c6c7f5b 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.html @@ -1,25 +1,25 @@ - - - -
- - - -

- - Is Authenticated: {{ isAuthenticated.isAuthenticated }} - -

- -
-
Data from direct API
-
-
{{ dataFromAzureProtectedApi$ | async | json }}
-
-
- -
- + + + +
+ + + +

+ + Is Authenticated: {{ isAuthenticated.isAuthenticated }} + +

+ +
+
Data from direct API
+
+
{{ dataFromAzureProtectedApi$ | async | json }}
+
+
+ +
+ diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.ts index 122d4e6..3051c27 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/directApiCall/directApiCall.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/directApiCall/directApiCall.component.ts @@ -1,34 +1,34 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { finalize } from 'rxjs/operators'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-direct-api-call', - templateUrl: 'directApiCall.component.html', -}) -export class DirectApiCallComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated$: Observable; - httpRequestRunning = false; - - constructor( - private authService: AuthService, - private httpClient: HttpClient - ) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.isAuthenticated$ = this.authService.signedIn$; - } - - callApi() { - this.httpRequestRunning = true; - this.dataFromAzureProtectedApi$ = this.httpClient - .get('https://localhost:44390/DirectApi') - .pipe(finalize(() => (this.httpRequestRunning = false))); - } -} +import { HttpClient } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { finalize } from 'rxjs/operators'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-direct-api-call', + templateUrl: 'directApiCall.component.html', +}) +export class DirectApiCallComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated$: Observable; + httpRequestRunning = false; + + constructor( + private authService: AuthService, + private httpClient: HttpClient + ) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.isAuthenticated$ = this.authService.signedIn$; + } + + callApi() { + this.httpRequestRunning = true; + this.dataFromAzureProtectedApi$ = this.httpClient + .get('https://localhost:44390/DirectApi') + .pipe(finalize(() => (this.httpRequestRunning = false))); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.html similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.html index c82d2d1..f7ef561 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.html @@ -1,25 +1,25 @@ - - - -
- - - -

- - Is Authenticated: {{ isAuthenticated.isAuthenticated }} - -

- -
-
Data from API using Graph API
-
-
{{ dataFromAzureProtectedApi$ | async | json }}
-
-
- -
- + + + +
+ + + +

+ + Is Authenticated: {{ isAuthenticated.isAuthenticated }} + +

+ +
+
Data from API using Graph API
+
+
{{ dataFromAzureProtectedApi$ | async | json }}
+
+
+ +
+ diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.ts index 7e260ac..2699834 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/graphApiCall/graphApiCall.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/graphApiCall/graphApiCall.component.ts @@ -1,33 +1,33 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { finalize } from 'rxjs/operators'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-graph-api-call', - templateUrl: 'graphApiCall.component.html', -}) -export class GraphApiCallComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated$: Observable; - httpRequestRunning = false; - constructor( - private authService: AuthService, - private httpClient: HttpClient - ) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.isAuthenticated$ = this.authService.signedIn$; - } - - callApi() { - this.httpRequestRunning = true; - this.dataFromAzureProtectedApi$ = this.httpClient - .get('https://localhost:44390/GraphApiCalls') - .pipe(finalize(() => (this.httpRequestRunning = false))); - } -} +import { HttpClient } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { finalize } from 'rxjs/operators'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-graph-api-call', + templateUrl: 'graphApiCall.component.html', +}) +export class GraphApiCallComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated$: Observable; + httpRequestRunning = false; + constructor( + private authService: AuthService, + private httpClient: HttpClient + ) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.isAuthenticated$ = this.authService.signedIn$; + } + + callApi() { + this.httpRequestRunning = true; + this.dataFromAzureProtectedApi$ = this.httpClient + .get('https://localhost:44390/GraphApiCalls') + .pipe(finalize(() => (this.httpRequestRunning = false))); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.html similarity index 94% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.html index 264e831..b80f72d 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.html @@ -1,16 +1,16 @@ - -
- - Is Authenticated: {{ isAuthenticated }} - -

- -
-
User Profile Data
-
-
{{ userData$ | async | json }}
-
-
- -
- + +
+ + Is Authenticated: {{ isAuthenticated }} + +

+ +
+
User Profile Data
+
+
{{ userData$ | async | json }}
+
+
+ +
+ diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.ts index 5395048..4cac944 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/home/home.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/home/home.component.ts @@ -1,34 +1,34 @@ -import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Observable } from 'rxjs'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-home', - templateUrl: 'home.component.html', -}) -export class HomeComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated = false; - constructor( - private authService: AuthService, - private httpClient: HttpClient - ) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.authService.signedIn$.subscribe(({ isAuthenticated }) => { - this.isAuthenticated = isAuthenticated; - - console.warn('authenticated: ', isAuthenticated); - }); - } - - callApi() { - this.dataFromAzureProtectedApi$ = this.httpClient.get( - 'https://localhost:44390/DirectApi' - ); - } -} +import { HttpClient } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Observable } from 'rxjs'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-home', + templateUrl: 'home.component.html', +}) +export class HomeComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated = false; + constructor( + private authService: AuthService, + private httpClient: HttpClient + ) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.authService.signedIn$.subscribe(({ isAuthenticated }) => { + this.isAuthenticated = isAuthenticated; + + console.warn('authenticated: ', isAuthenticated); + }); + } + + callApi() { + this.dataFromAzureProtectedApi$ = this.httpClient.get( + 'https://localhost:44390/DirectApi' + ); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.css similarity index 95% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.css index f76d035..e15c612 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.css +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.css @@ -1,59 +1,59 @@ -li .glyphicon { - margin-right: 10px; -} - -/* Highlighting rules for nav menu items */ -li.link-active a, -li.link-active a:hover, -li.link-active a:focus { - background-color: #4189C7; - color: white; -} - -/* Keep the nav menu independent of scrolling and on top of other items */ -.main-nav { - position: fixed; - top: 0; - left: 0; - right: 0; - z-index: 1; -} - -@media (min-width: 768px) { - /* On small screens, convert the nav menu to a vertical sidebar */ - .main-nav { - height: 100%; - width: calc(25% - 20px); - } - .navbar { - border-radius: 0px; - border-width: 0px; - height: 100%; - } - .navbar-header { - float: none; - } - .navbar-collapse { - border-top: 1px solid #444; - padding: 0px; - } - .navbar ul { - float: none; - } - .navbar li { - float: none; - font-size: 15px; - margin: 6px; - } - .navbar li a { - padding: 10px 16px; - border-radius: 4px; - } - .navbar a { - /* If a menu item's text is too long, truncate it */ - width: 100%; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } -} +li .glyphicon { + margin-right: 10px; +} + +/* Highlighting rules for nav menu items */ +li.link-active a, +li.link-active a:hover, +li.link-active a:focus { + background-color: #4189C7; + color: white; +} + +/* Keep the nav menu independent of scrolling and on top of other items */ +.main-nav { + position: fixed; + top: 0; + left: 0; + right: 0; + z-index: 1; +} + +@media (min-width: 768px) { + /* On small screens, convert the nav menu to a vertical sidebar */ + .main-nav { + height: 100%; + width: calc(25% - 20px); + } + .navbar { + border-radius: 0px; + border-width: 0px; + height: 100%; + } + .navbar-header { + float: none; + } + .navbar-collapse { + border-top: 1px solid #444; + padding: 0px; + } + .navbar ul { + float: none; + } + .navbar li { + float: none; + font-size: 15px; + margin: 6px; + } + .navbar li a { + padding: 10px 16px; + border-radius: 4px; + } + .navbar a { + /* If a menu item's text is too long, truncate it */ + width: 100%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.html similarity index 97% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.html index 6cd21d5..20a3cdd 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.html +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.html @@ -1,44 +1,44 @@ - - + + diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.ts similarity index 96% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.ts index 02d80d8..fd0f956 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/nav-menu/nav-menu.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/nav-menu/nav-menu.component.ts @@ -1,39 +1,39 @@ -import { AuthenticatedResult } from 'angular-auth-oidc-client'; -import { Component, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; -import { AuthService } from '../auth.service'; - -@Component({ - selector: 'app-nav-menu', - templateUrl: './nav-menu.component.html', - styleUrls: ['./nav-menu.component.css'], -}) -export class NavMenuComponent implements OnInit { - userData$: Observable; - dataFromAzureProtectedApi$: Observable; - isAuthenticated = false; - constructor(private authService: AuthService) {} - - ngOnInit() { - this.userData$ = this.authService.userData$; - this.authService.signedIn$.subscribe(({ isAuthenticated }) => { - this.isAuthenticated = isAuthenticated; - - console.warn('authenticated: ', isAuthenticated); - }); - } - - login() { - this.authService.signIn(); - } - - forceRefreshSession() { - this.authService.forceRefreshSession().subscribe((data) => { - console.log('Refresh completed'); - }); - } - - logout() { - this.authService.signOut(); - } -} +import { AuthenticatedResult } from 'angular-auth-oidc-client'; +import { Component, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-nav-menu', + templateUrl: './nav-menu.component.html', + styleUrls: ['./nav-menu.component.css'], +}) +export class NavMenuComponent implements OnInit { + userData$: Observable; + dataFromAzureProtectedApi$: Observable; + isAuthenticated = false; + constructor(private authService: AuthService) {} + + ngOnInit() { + this.userData$ = this.authService.userData$; + this.authService.signedIn$.subscribe(({ isAuthenticated }) => { + this.isAuthenticated = isAuthenticated; + + console.warn('authenticated: ', isAuthenticated); + }); + } + + login() { + this.authService.signIn(); + } + + forceRefreshSession() { + this.authService.forceRefreshSession().subscribe((data) => { + console.log('Refresh completed'); + }); + } + + logout() { + this.authService.signOut(); + } +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.html similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.html diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.ts similarity index 95% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.ts index 1249768..f3947f7 100644 --- a/AngularAzureADMultipleApis/AngularCliAzureAD/src/app/unauthorized/unauthorized.component.ts +++ b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/app/unauthorized/unauthorized.component.ts @@ -1,11 +1,11 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'app-unauthorized', - templateUrl: 'unauthorized.component.html', -}) -export class UnauthorizedComponent implements OnInit { - constructor() {} - - ngOnInit() {} -} +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-unauthorized', + templateUrl: 'unauthorized.component.html', +}) +export class UnauthorizedComponent implements OnInit { + constructor() {} + + ngOnInit() {} +} diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/assets/.gitkeep b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/assets/.gitkeep similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/assets/.gitkeep rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/assets/.gitkeep diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/environments/environment.prod.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/environments/environment.prod.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/environments/environment.prod.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/environments/environment.prod.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/environments/environment.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/environments/environment.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/environments/environment.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/environments/environment.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/favicon.ico b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/favicon.ico similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/favicon.ico rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/favicon.ico diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/index.html b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/index.html similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/index.html rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/index.html diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/main.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/main.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/main.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/main.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/polyfills.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/polyfills.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/polyfills.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/polyfills.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/styles.css b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/styles.css similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/styles.css rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/styles.css diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/src/test.ts b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/test.ts similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/src/test.ts rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/src/test.ts diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.app.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.app.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.app.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.app.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.json diff --git a/AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.spec.json b/AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.spec.json similarity index 100% rename from AngularAzureADMultipleApis/AngularCliAzureAD/tsconfig.spec.json rename to AngularMicrsoftEntraIDMultipleApis/AngularCliMicrsoftEntraID/tsconfig.spec.json diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis.sln b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis.sln similarity index 98% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis.sln rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis.sln index fcacf9c..cc09c58 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis.sln +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis.sln @@ -1,43 +1,43 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30717.126 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceApi", "ServiceApi\ServiceApi.csproj", "{DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserApi", "UserApi\UserApi.csproj", "{80697F19-EFA0-4268-B56B-B6262B5BBD01}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiWithMutlipleApis", "ApiWithMutlipleApis\ApiWithMutlipleApis.csproj", "{0151C102-3123-4D5B-A76D-FBCAAF90CAAA}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D041721B-5836-402C-8F6C-5E1F556180CD}" - ProjectSection(SolutionItems) = preProject - ..\README.md = ..\README.md - README_CONFIG.md = README_CONFIG.md - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Release|Any CPU.Build.0 = Release|Any CPU - {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Debug|Any CPU.Build.0 = Debug|Any CPU - {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Release|Any CPU.ActiveCfg = Release|Any CPU - {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Release|Any CPU.Build.0 = Release|Any CPU - {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {33DBE2BB-67F6-4610-87A8-25C015549C23} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceApi", "ServiceApi\ServiceApi.csproj", "{DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserApi", "UserApi\UserApi.csproj", "{80697F19-EFA0-4268-B56B-B6262B5BBD01}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiWithMutlipleApis", "ApiWithMutlipleApis\ApiWithMutlipleApis.csproj", "{0151C102-3123-4D5B-A76D-FBCAAF90CAAA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D041721B-5836-402C-8F6C-5E1F556180CD}" + ProjectSection(SolutionItems) = preProject + ..\README.md = ..\README.md + README_CONFIG.md = README_CONFIG.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB5BD1DB-0EF8-4D8C-A2A8-BF5E29782973}.Release|Any CPU.Build.0 = Release|Any CPU + {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80697F19-EFA0-4268-B56B-B6262B5BBD01}.Release|Any CPU.Build.0 = Release|Any CPU + {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0151C102-3123-4D5B-A76D-FBCAAF90CAAA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {33DBE2BB-67F6-4610-87A8-25C015549C23} + EndGlobalSection +EndGlobal diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj similarity index 98% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj index 7193cdf..2c7c869 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/ApiWithMutlipleApis.csproj @@ -1,32 +1,32 @@ - - - - net8.0 - 3e9ac996-8e75-4dd9-9a5b-27a6e01a3f3d - enable - enable - - - - - - - - - - - - - - - - - - - - - - - - - + + + + net8.0 + 3e9ac996-8e75-4dd9-9a5b-27a6e01a3f3d + enable + enable + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs similarity index 97% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs index 4566458..7b2838e 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DelegatedUserApiCallsController.cs @@ -1,27 +1,27 @@ -using ApiWithMutlipleApis.Services; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Identity.Web; - -namespace ApiWithMutlipleApis.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] -[ApiController] -[Route("[controller]")] -public class DelegatedUserApiCallsController : ControllerBase -{ - private UserApiClientService _userApiClientService; - - public DelegatedUserApiCallsController(UserApiClientService userApiClientService) - { - _userApiClientService = userApiClientService; - } - - [HttpGet] - public async Task> Get() - { - return await _userApiClientService.GetApiDataAsync(); - } -} +using ApiWithMutlipleApis.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Identity.Web; + +namespace ApiWithMutlipleApis.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] +[ApiController] +[Route("[controller]")] +public class DelegatedUserApiCallsController : ControllerBase +{ + private UserApiClientService _userApiClientService; + + public DelegatedUserApiCallsController(UserApiClientService userApiClientService) + { + _userApiClientService = userApiClientService; + } + + [HttpGet] + public async Task> Get() + { + return await _userApiClientService.GetApiDataAsync(); + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs similarity index 97% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs index 61e94e3..7f0350f 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/DirectApiController.cs @@ -1,20 +1,20 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Identity.Web; - -namespace ApiWithMutlipleApis.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", - AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] -[ApiController] -[Route("[controller]")] -public class DirectApiController : ControllerBase -{ - [HttpGet] - public IEnumerable Get() - { - return new List { "some data", "more data", "loads of data" }; - } -} +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Identity.Web; + +namespace ApiWithMutlipleApis.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", + AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] +[ApiController] +[Route("[controller]")] +public class DirectApiController : ControllerBase +{ + [HttpGet] + public IEnumerable Get() + { + return new List { "some data", "more data", "loads of data" }; + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs similarity index 97% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs index 91cc7c6..4778259 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/GraphApiCallsController.cs @@ -1,30 +1,30 @@ -using ApiWithMutlipleApis.Services; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Identity.Web; - -namespace ApiWithMutlipleApis.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[AuthorizeForScopes(Scopes = new string[] { "User.ReadBasic.All", "user.read" })] -[ApiController] -[Route("[controller]")] -public class GraphApiCallsController : ControllerBase -{ - private GraphApiClientService _graphApiClientService; - - public GraphApiCallsController(GraphApiClientService graphApiClientService) - { - _graphApiClientService = graphApiClientService; - } - - [HttpGet] - public async Task> Get() - { - var userData = await _graphApiClientService.GetGraphApiUser(); - - return new List { $"DisplayName: {userData.DisplayName}", - $"GivenName: {userData.GivenName}", $"AboutMe: {userData.AboutMe}" }; - } -} +using ApiWithMutlipleApis.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Identity.Web; + +namespace ApiWithMutlipleApis.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[AuthorizeForScopes(Scopes = new string[] { "User.ReadBasic.All", "user.read" })] +[ApiController] +[Route("[controller]")] +public class GraphApiCallsController : ControllerBase +{ + private GraphApiClientService _graphApiClientService; + + public GraphApiCallsController(GraphApiClientService graphApiClientService) + { + _graphApiClientService = graphApiClientService; + } + + [HttpGet] + public async Task> Get() + { + var userData = await _graphApiClientService.GetGraphApiUser(); + + return new List { $"DisplayName: {userData.DisplayName}", + $"GivenName: {userData.GivenName}", $"AboutMe: {userData.AboutMe}" }; + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs similarity index 97% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs index b2ec883..605b627 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Controllers/ServiceApiCallsController.cs @@ -1,27 +1,27 @@ -using ApiWithMutlipleApis.Services; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Identity.Web; - -namespace ApiWithMutlipleApis.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] -[ApiController] -[Route("[controller]")] -public class ServiceApiCallsController : ControllerBase -{ - private ServiceApiClientService _serviceApiClientService; - - public ServiceApiCallsController(ServiceApiClientService serviceApiClientService) - { - _serviceApiClientService = serviceApiClientService; - } - - [HttpGet] - public async Task> Get() - { - return await _serviceApiClientService.GetApiDataAsync(); - } -} +using ApiWithMutlipleApis.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Identity.Web; + +namespace ApiWithMutlipleApis.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })] +[ApiController] +[Route("[controller]")] +public class ServiceApiCallsController : ControllerBase +{ + private ServiceApiClientService _serviceApiClientService; + + public ServiceApiCallsController(ServiceApiClientService serviceApiClientService) + { + _serviceApiClientService = serviceApiClientService; + } + + [HttpGet] + public async Task> Get() + { + return await _serviceApiClientService.GetApiDataAsync(); + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/HostingExtensions.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/HostingExtensions.cs similarity index 100% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/HostingExtensions.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/HostingExtensions.cs diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Program.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Program.cs similarity index 95% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Program.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Program.cs index 6fa901c..7e4ad58 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Program.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Program.cs @@ -1,34 +1,34 @@ -using ApiWithMutlipleApis; -using Serilog; - -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .WriteTo.AzureApp() - .CreateBootstrapLogger(); - -try -{ - Log.Information("Starting ApiWithMutlipleApis"); - -var builder = WebApplication.CreateBuilder(args); - - -builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration - .ReadFrom.Configuration(context.Configuration)); - -var app = builder - .ConfigureServices() - .ConfigurePipeline(); - -app.Run(); -} -catch (Exception ex) when(ex.GetType().Name is not "StopTheHostException" - && ex.GetType().Name is not "HostAbortedException") -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} +using ApiWithMutlipleApis; +using Serilog; + +Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .WriteTo.AzureApp() + .CreateBootstrapLogger(); + +try +{ + Log.Information("Starting ApiWithMutlipleApis"); + +var builder = WebApplication.CreateBuilder(args); + + +builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration + .ReadFrom.Configuration(context.Configuration)); + +var app = builder + .ConfigureServices() + .ConfigurePipeline(); + +app.Run(); +} +catch (Exception ex) when(ex.GetType().Name is not "StopTheHostException" + && ex.GetType().Name is not "HostAbortedException") +{ + Log.Fatal(ex, "Unhandled exception"); +} +finally +{ + Log.Information("Shut down complete"); + Log.CloseAndFlush(); +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json similarity index 95% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json index 5995318..6683ef5 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Properties/launchSettings.json @@ -1,13 +1,13 @@ -{ - "profiles": { - "ApiWithMutlipleApis": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:44390" - } - } +{ + "profiles": { + "ApiWithMutlipleApis": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:44390" + } + } } \ No newline at end of file diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs similarity index 96% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs index a0eb8e9..2e1deb5 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs @@ -1,56 +1,56 @@ -using ImageMagick; -using Microsoft.Graph; -using Microsoft.Graph.Models; -using Microsoft.Identity.Web; -using Microsoft.IdentityModel.Tokens; - -namespace ApiWithMutlipleApis.Services; - -public class GraphApiClientService -{ - private readonly GraphServiceClient _graphServiceClient; - - public GraphApiClientService(GraphServiceClient graphServiceClient) - { - _graphServiceClient = graphServiceClient; - } - - public async Task GetGraphApiUser() - { - var user = await _graphServiceClient.Me - .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read")); - - return user; - } - - public async Task GetGraphApiProfilePhoto(string oid) - { - var photo = string.Empty; - byte[] photoByte; - - using (var photoStream = await _graphServiceClient.Users[oid] - .Photo - .Content - .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) - { - photoByte = ((MemoryStream)photoStream!).ToArray(); - } - - using var imageFromFile = new MagickImage(photoByte); - // Sets the output format to jpeg - imageFromFile.Format = MagickFormat.Jpeg; - var size = new MagickGeometry(400, 400); - - // This will resize the image to a fixed size without maintaining the aspect ratio. - // Normally an image will be resized to fit inside the specified size. - //size.IgnoreAspectRatio = true; - - imageFromFile.Resize(size); - - // Create byte array that contains a jpeg file - var data = imageFromFile.ToByteArray(); - photo = Base64UrlEncoder.Encode(data); - - return photo; - } -} +using ImageMagick; +using Microsoft.Graph; +using Microsoft.Graph.Models; +using Microsoft.Identity.Web; +using Microsoft.IdentityModel.Tokens; + +namespace ApiWithMutlipleApis.Services; + +public class GraphApiClientService +{ + private readonly GraphServiceClient _graphServiceClient; + + public GraphApiClientService(GraphServiceClient graphServiceClient) + { + _graphServiceClient = graphServiceClient; + } + + public async Task GetGraphApiUser() + { + var user = await _graphServiceClient.Me + .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read")); + + return user; + } + + public async Task GetGraphApiProfilePhoto(string oid) + { + var photo = string.Empty; + byte[] photoByte; + + using (var photoStream = await _graphServiceClient.Users[oid] + .Photo + .Content + .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) + { + photoByte = ((MemoryStream)photoStream!).ToArray(); + } + + using var imageFromFile = new MagickImage(photoByte); + // Sets the output format to jpeg + imageFromFile.Format = MagickFormat.Jpeg; + var size = new MagickGeometry(400, 400); + + // This will resize the image to a fixed size without maintaining the aspect ratio. + // Normally an image will be resized to fit inside the specified size. + //size.IgnoreAspectRatio = true; + + imageFromFile.Resize(size); + + // Create byte array that contains a jpeg file + var data = imageFromFile.ToByteArray(); + photo = Base64UrlEncoder.Encode(data); + + return photo; + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs similarity index 97% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs index 8d044d7..5a9cbcd 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/ServiceApiClientService.cs @@ -1,47 +1,47 @@ -using Microsoft.Identity.Web; -using System.Net.Http.Headers; -using System.Text.Json; - -namespace ApiWithMutlipleApis.Services; - -public class ServiceApiClientService -{ - private readonly IHttpClientFactory _clientFactory; - private readonly ITokenAcquisition _tokenAcquisition; - - public ServiceApiClientService( - ITokenAcquisition tokenAcquisition, - IHttpClientFactory clientFactory) - { - _clientFactory = clientFactory; - _tokenAcquisition = tokenAcquisition; - } - - public async Task> GetApiDataAsync() - { - - var client = _clientFactory.CreateClient(); - - var scope = "api://b178f3a5-7588-492a-924f-72d7887b7e48/.default"; // CC flow access_as_application"; - var accessToken = await _tokenAcquisition.GetAccessTokenForAppAsync(scope) - .ConfigureAwait(false); - - client.BaseAddress = new Uri("https://localhost:44324"); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - var response = await client.GetAsync("ApiForServiceData"); - if (response.IsSuccessStatusCode) - { - var data = await JsonSerializer.DeserializeAsync>( - await response.Content.ReadAsStreamAsync()); - - if(data != null) - return data; - - return Array.Empty(); - } - - throw new ApplicationException("oh no..."); - } -} +using Microsoft.Identity.Web; +using System.Net.Http.Headers; +using System.Text.Json; + +namespace ApiWithMutlipleApis.Services; + +public class ServiceApiClientService +{ + private readonly IHttpClientFactory _clientFactory; + private readonly ITokenAcquisition _tokenAcquisition; + + public ServiceApiClientService( + ITokenAcquisition tokenAcquisition, + IHttpClientFactory clientFactory) + { + _clientFactory = clientFactory; + _tokenAcquisition = tokenAcquisition; + } + + public async Task> GetApiDataAsync() + { + + var client = _clientFactory.CreateClient(); + + var scope = "api://b178f3a5-7588-492a-924f-72d7887b7e48/.default"; // CC flow access_as_application"; + var accessToken = await _tokenAcquisition.GetAccessTokenForAppAsync(scope) + .ConfigureAwait(false); + + client.BaseAddress = new Uri("https://localhost:44324"); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + + var response = await client.GetAsync("ApiForServiceData"); + if (response.IsSuccessStatusCode) + { + var data = await JsonSerializer.DeserializeAsync>( + await response.Content.ReadAsStreamAsync()); + + if(data != null) + return data; + + return Array.Empty(); + } + + throw new ApplicationException("oh no..."); + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs similarity index 96% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs index c2f1661..7b4fedf 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/UserApiClientService.cs @@ -1,48 +1,48 @@ -using Microsoft.Identity.Web; -using System.Net.Http.Headers; -using System.Text.Json; - -namespace ApiWithMutlipleApis.Services; - -public class UserApiClientService -{ - private readonly IHttpClientFactory _clientFactory; - private readonly ITokenAcquisition _tokenAcquisition; - - public UserApiClientService( - ITokenAcquisition tokenAcquisition, - IHttpClientFactory clientFactory) - { - _clientFactory = clientFactory; - _tokenAcquisition = tokenAcquisition; - } - - public async Task> GetApiDataAsync() - { - - var client = _clientFactory.CreateClient(); - - var scopes = new List { "api://b2a09168-54e2-4bc4-af92-a710a64ef1fa/access_as_user" }; - var accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(scopes); - - client.BaseAddress = new Uri("https://localhost:44395"); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - var response = await client.GetAsync("ApiForUserData"); - - if (response.IsSuccessStatusCode) - { - var stream = await response.Content.ReadAsStreamAsync(); - - var data = await JsonSerializer.DeserializeAsync>(stream); - - if (data != null) - return data; - - return Array.Empty(); - } - - throw new ApplicationException("oh no..."); - } -} +using Microsoft.Identity.Web; +using System.Net.Http.Headers; +using System.Text.Json; + +namespace ApiWithMutlipleApis.Services; + +public class UserApiClientService +{ + private readonly IHttpClientFactory _clientFactory; + private readonly ITokenAcquisition _tokenAcquisition; + + public UserApiClientService( + ITokenAcquisition tokenAcquisition, + IHttpClientFactory clientFactory) + { + _clientFactory = clientFactory; + _tokenAcquisition = tokenAcquisition; + } + + public async Task> GetApiDataAsync() + { + + var client = _clientFactory.CreateClient(); + + var scopes = new List { "api://b2a09168-54e2-4bc4-af92-a710a64ef1fa/access_as_user" }; + var accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(scopes); + + client.BaseAddress = new Uri("https://localhost:44395"); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + + var response = await client.GetAsync("ApiForUserData"); + + if (response.IsSuccessStatusCode) + { + var stream = await response.Content.ReadAsStreamAsync(); + + var data = await JsonSerializer.DeserializeAsync>(stream); + + if (data != null) + return data; + + return Array.Empty(); + } + + throw new ApplicationException("oh no..."); + } +} diff --git a/AngularAzureADMultipleApis/ApiWithMutlipleApis/appsettings.json b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/appsettings.json similarity index 96% rename from AngularAzureADMultipleApis/ApiWithMutlipleApis/appsettings.json rename to AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/appsettings.json index 0b94580..56e184e 100644 --- a/AngularAzureADMultipleApis/ApiWithMutlipleApis/appsettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/ApiWithMutlipleApis/appsettings.json @@ -1,40 +1,40 @@ -{ - "AzureAd": { - "Instance": "https://login.microsoftonline.com/", - "Domain": "damienbodhotmail.onmicrosoft.com", - "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", - "ClientId": "2b50a014-f353-4c10-aace-024f19a55569" - }, - "Serilog": { - "Using": [ "Serilog.Sinks.Console" ], - "MinimumLevel": { - "Default": "Debug", - "Override": { - "Microsoft": "Debug", - "Microsoft.EntityFrameworkCore": "Warning", - "System": "Debug" - } - }, - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], - "WriteTo": [ - { - "Name": "Console", - "Args": { - "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", - "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} ({SourceContext}){NewLine}{Exception}" - } - }, - { - "Name": "File", - "Args": { - "path": "../_logs-ApiWithMutlipleApis.txt", - "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}", - "rollOnFileSizeLimit": true, - "fileSizeLimitBytes": 4194304, - "retainedFileCountLimit": 5 - } - } - ] - }, - "AllowedHosts": "*" -} +{ + "AzureAd": { + "Instance": "https://login.microsoftonline.com/", + "Domain": "damienbodhotmail.onmicrosoft.com", + "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", + "ClientId": "2b50a014-f353-4c10-aace-024f19a55569" + }, + "Serilog": { + "Using": [ "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Debug", + "Override": { + "Microsoft": "Debug", + "Microsoft.EntityFrameworkCore": "Warning", + "System": "Debug" + } + }, + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", + "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} ({SourceContext}){NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "../_logs-ApiWithMutlipleApis.txt", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}", + "rollOnFileSizeLimit": true, + "fileSizeLimitBytes": 4194304, + "retainedFileCountLimit": 5 + } + } + ] + }, + "AllowedHosts": "*" +} diff --git a/AngularAzureADMultipleApis/README_CONFIG.md b/AngularMicrsoftEntraIDMultipleApis/README_CONFIG.md similarity index 92% rename from AngularAzureADMultipleApis/README_CONFIG.md rename to AngularMicrsoftEntraIDMultipleApis/README_CONFIG.md index 22a8715..a1ed98c 100644 --- a/AngularAzureADMultipleApis/README_CONFIG.md +++ b/AngularMicrsoftEntraIDMultipleApis/README_CONFIG.md @@ -1,8 +1,8 @@ - -## ApiWithMutlipleApis secrets - -``` - "AzureAd": { - "ClientSecret": "your-secret" - } + +## ApiWithMutlipleApis secrets + +``` + "AzureAd": { + "ClientSecret": "your-secret" + } ``` \ No newline at end of file diff --git a/AngularAzureADMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs similarity index 97% rename from AngularAzureADMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs index 1434686..8014f9b 100644 --- a/AngularAzureADMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Controllers/ApiForServiceDataController.cs @@ -1,26 +1,26 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; - -namespace ServiceApi.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[ApiController] -[Route("[controller]")] -[ProducesResponseType(StatusCodes.Status401Unauthorized)] -[ProducesResponseType(StatusCodes.Status403Forbidden)] -[Produces("application/json")] -[SwaggerTag("Service API for demo service data")] -public class ApiForServiceDataController : ControllerBase -{ - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] - [SwaggerOperation(OperationId = "Get", Summary = "Gets service data")] - public IEnumerable Get() - { - return new List { "app-app Service API data 1", "service API data 2" }; - } -} +using System.Collections.Generic; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; + +namespace ServiceApi.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[ApiController] +[Route("[controller]")] +[ProducesResponseType(StatusCodes.Status401Unauthorized)] +[ProducesResponseType(StatusCodes.Status403Forbidden)] +[Produces("application/json")] +[SwaggerTag("Service API for demo service data")] +public class ApiForServiceDataController : ControllerBase +{ + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [SwaggerOperation(OperationId = "Get", Summary = "Gets service data")] + public IEnumerable Get() + { + return new List { "app-app Service API data 1", "service API data 2" }; + } +} diff --git a/AngularAzureADMultipleApis/ServiceApi/HostingExtensions.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/HostingExtensions.cs similarity index 100% rename from AngularAzureADMultipleApis/ServiceApi/HostingExtensions.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/HostingExtensions.cs diff --git a/AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs similarity index 96% rename from AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs index 9864988..e3839fb 100644 --- a/AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleHandler.cs @@ -1,42 +1,42 @@ -using Microsoft.AspNetCore.Authorization; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; - -namespace ServiceApi; - -public class HasServiceApiRoleHandler : AuthorizationHandler -{ - protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasServiceApiRoleRequirement requirement) - { - if (context == null) - throw new ArgumentNullException(nameof(context)); - if (requirement == null) - throw new ArgumentNullException(nameof(requirement)); - - var roleClaims = context.User.Claims.Where(t => t.Type == "roles"); - - if (roleClaims != null && HasServiceApiRole(roleClaims)) - { - context.Succeed(requirement); - } - - return Task.CompletedTask; - } - - private static bool HasServiceApiRole(IEnumerable roleClaims) - { - // we could also validate the "access_as_application" scope - foreach (var role in roleClaims) - { - if ("service-api" == role.Value) - { - return true; - } - } - - return false; - } +using Microsoft.AspNetCore.Authorization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; + +namespace ServiceApi; + +public class HasServiceApiRoleHandler : AuthorizationHandler +{ + protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasServiceApiRoleRequirement requirement) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); + if (requirement == null) + throw new ArgumentNullException(nameof(requirement)); + + var roleClaims = context.User.Claims.Where(t => t.Type == "roles"); + + if (roleClaims != null && HasServiceApiRole(roleClaims)) + { + context.Succeed(requirement); + } + + return Task.CompletedTask; + } + + private static bool HasServiceApiRole(IEnumerable roleClaims) + { + // we could also validate the "access_as_application" scope + foreach (var role in roleClaims) + { + if ("service-api" == role.Value) + { + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs similarity index 97% rename from AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs index 0e7bc0d..fd0731e 100644 --- a/AngularAzureADMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Policies/HasServiceApiRoleRequirement.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNetCore.Authorization; - -namespace ServiceApi; - +using Microsoft.AspNetCore.Authorization; + +namespace ServiceApi; + public class HasServiceApiRoleRequirement : IAuthorizationRequirement { } \ No newline at end of file diff --git a/AngularAzureADMultipleApis/ServiceApi/Program.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Program.cs similarity index 96% rename from AngularAzureADMultipleApis/ServiceApi/Program.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/Program.cs index 6531f82..773fa7f 100644 --- a/AngularAzureADMultipleApis/ServiceApi/Program.cs +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Program.cs @@ -1,57 +1,57 @@ -using ServiceApi; -using Azure.Identity; -using Serilog; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using System; - -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .WriteTo.AzureApp() - .CreateBootstrapLogger(); - -try -{ - Log.Information("Starting WebApi"); - - var builder = WebApplication.CreateBuilder(args); - - builder.WebHost - .ConfigureKestrel(serverOptions => { serverOptions.AddServerHeader = false; }) - .ConfigureAppConfiguration((context, configurationBuilder) => - { - var config = configurationBuilder.Build(); - var azureKeyVaultEndpoint = config["AzureKeyVaultEndpoint"]; - if (!string.IsNullOrEmpty(azureKeyVaultEndpoint)) - { - // Add Secrets from KeyVault - Log.Information("Use secrets from {AzureKeyVaultEndpoint}", azureKeyVaultEndpoint); - configurationBuilder.AddAzureKeyVault(new Uri(azureKeyVaultEndpoint), new DefaultAzureCredential()); - } - else - { - // Add Secrets from UserSecrets for local development - configurationBuilder.AddUserSecrets("9f17b08c-435a-4f50-ba7a-802e68ca8d80"); - } - }); - - builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration - .ReadFrom.Configuration(context.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" - && ex.GetType().Name is not "HostAbortedException") -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} +using ServiceApi; +using Azure.Identity; +using Serilog; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using System; + +Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .WriteTo.AzureApp() + .CreateBootstrapLogger(); + +try +{ + Log.Information("Starting WebApi"); + + var builder = WebApplication.CreateBuilder(args); + + builder.WebHost + .ConfigureKestrel(serverOptions => { serverOptions.AddServerHeader = false; }) + .ConfigureAppConfiguration((context, configurationBuilder) => + { + var config = configurationBuilder.Build(); + var azureKeyVaultEndpoint = config["AzureKeyVaultEndpoint"]; + if (!string.IsNullOrEmpty(azureKeyVaultEndpoint)) + { + // Add Secrets from KeyVault + Log.Information("Use secrets from {AzureKeyVaultEndpoint}", azureKeyVaultEndpoint); + configurationBuilder.AddAzureKeyVault(new Uri(azureKeyVaultEndpoint), new DefaultAzureCredential()); + } + else + { + // Add Secrets from UserSecrets for local development + configurationBuilder.AddUserSecrets("9f17b08c-435a-4f50-ba7a-802e68ca8d80"); + } + }); + + builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration + .ReadFrom.Configuration(context.Configuration)); + + var app = builder + .ConfigureServices() + .ConfigurePipeline(); + + app.Run(); +} +catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" + && ex.GetType().Name is not "HostAbortedException") +{ + Log.Fatal(ex, "Unhandled exception"); +} +finally +{ + Log.Information("Shut down complete"); + Log.CloseAndFlush(); +} diff --git a/AngularAzureADMultipleApis/ServiceApi/Properties/launchSettings.json b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Properties/launchSettings.json similarity index 95% rename from AngularAzureADMultipleApis/ServiceApi/Properties/launchSettings.json rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/Properties/launchSettings.json index db40bbb..68bcdbb 100644 --- a/AngularAzureADMultipleApis/ServiceApi/Properties/launchSettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/Properties/launchSettings.json @@ -1,13 +1,13 @@ -{ - "profiles": { - "ServiceApi": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:44324" - } - } +{ + "profiles": { + "ServiceApi": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:44324" + } + } } \ No newline at end of file diff --git a/AngularAzureADMultipleApis/ServiceApi/SecurityHeadersDefinitions.cs b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/SecurityHeadersDefinitions.cs similarity index 100% rename from AngularAzureADMultipleApis/ServiceApi/SecurityHeadersDefinitions.cs rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/SecurityHeadersDefinitions.cs diff --git a/AngularAzureADMultipleApis/ServiceApi/ServiceApi.csproj b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/ServiceApi.csproj similarity index 98% rename from AngularAzureADMultipleApis/ServiceApi/ServiceApi.csproj rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/ServiceApi.csproj index 5439c67..365b465 100644 --- a/AngularAzureADMultipleApis/ServiceApi/ServiceApi.csproj +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/ServiceApi.csproj @@ -1,30 +1,30 @@ - - - - net8.0 - 196b270c-b0c0-4b90-8f04-d3108e701d51 - enable - - - - - - - - - - - - - - - - - - - - - - - - + + + + net8.0 + 196b270c-b0c0-4b90-8f04-d3108e701d51 + enable + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AngularAzureADMultipleApis/ServiceApi/appsettings.json b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/appsettings.json similarity index 96% rename from AngularAzureADMultipleApis/ServiceApi/appsettings.json rename to AngularMicrsoftEntraIDMultipleApis/ServiceApi/appsettings.json index a66eb02..a1030f4 100644 --- a/AngularAzureADMultipleApis/ServiceApi/appsettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/ServiceApi/appsettings.json @@ -1,40 +1,40 @@ -{ - "AzureAd": { - "Instance": "https://login.microsoftonline.com/", - "Domain": "damienbodhotmail.onmicrosoft.com", - "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", - "ClientId": "b178f3a5-7588-492a-924f-72d7887b7e48" - }, - "Serilog": { - "Using": [ "Serilog.Sinks.Console" ], - "MinimumLevel": { - "Default": "Debug", - "Override": { - "Microsoft": "Debug", - "Microsoft.EntityFrameworkCore": "Warning", - "System": "Debug" - } - }, - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], - "WriteTo": [ - { - "Name": "Console", - "Args": { - "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", - "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} ({SourceContext}){NewLine}{Exception}" - } - }, - { - "Name": "File", - "Args": { - "path": "../_logs-ServiceApi.txt", - "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}", - "rollOnFileSizeLimit": true, - "fileSizeLimitBytes": 4194304, - "retainedFileCountLimit": 5 - } - } - ] - }, - "AllowedHosts": "*" -} +{ + "AzureAd": { + "Instance": "https://login.microsoftonline.com/", + "Domain": "damienbodhotmail.onmicrosoft.com", + "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", + "ClientId": "b178f3a5-7588-492a-924f-72d7887b7e48" + }, + "Serilog": { + "Using": [ "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Debug", + "Override": { + "Microsoft": "Debug", + "Microsoft.EntityFrameworkCore": "Warning", + "System": "Debug" + } + }, + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", + "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} ({SourceContext}){NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "../_logs-ServiceApi.txt", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}", + "rollOnFileSizeLimit": true, + "fileSizeLimitBytes": 4194304, + "retainedFileCountLimit": 5 + } + } + ] + }, + "AllowedHosts": "*" +} diff --git a/AngularAzureADMultipleApis/UserApi/Controllers/ApiForUserDataController.cs b/AngularMicrsoftEntraIDMultipleApis/UserApi/Controllers/ApiForUserDataController.cs similarity index 96% rename from AngularAzureADMultipleApis/UserApi/Controllers/ApiForUserDataController.cs rename to AngularMicrsoftEntraIDMultipleApis/UserApi/Controllers/ApiForUserDataController.cs index e979db6..cd13850 100644 --- a/AngularAzureADMultipleApis/UserApi/Controllers/ApiForUserDataController.cs +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/Controllers/ApiForUserDataController.cs @@ -1,17 +1,17 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace UserApiOne.Controllers; - -[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -[ApiController] -[Route("[controller]")] -public class ApiForUserDataController : ControllerBase -{ - [HttpGet] - public IEnumerable Get() - { - return new List { "user API data 1", "user API data 2" }; - } -} +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace UserApiOne.Controllers; + +[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +[ApiController] +[Route("[controller]")] +public class ApiForUserDataController : ControllerBase +{ + [HttpGet] + public IEnumerable Get() + { + return new List { "user API data 1", "user API data 2" }; + } +} diff --git a/AngularAzureADMultipleApis/UserApi/Program.cs b/AngularMicrsoftEntraIDMultipleApis/UserApi/Program.cs similarity index 96% rename from AngularAzureADMultipleApis/UserApi/Program.cs rename to AngularMicrsoftEntraIDMultipleApis/UserApi/Program.cs index c0e211a..6fb33e3 100644 --- a/AngularAzureADMultipleApis/UserApi/Program.cs +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/Program.cs @@ -1,103 +1,103 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc.Authorization; -using Microsoft.Identity.Web; -using Microsoft.IdentityModel.Logging; -using Microsoft.OpenApi.Models; -using System.IdentityModel.Tokens.Jwt; - -var builder = WebApplication.CreateBuilder(args); - -builder.Services - .AddMicrosoftIdentityWebApiAuthentication(builder.Configuration); - -builder.Services.AddControllers(options => -{ - var policy = new AuthorizationPolicyBuilder() - .RequireAuthenticatedUser() - .Build(); - options.Filters.Add(new AuthorizeFilter(policy)); -}); - -builder.Services.AddAuthorization(options => -{ - options.AddPolicy("ValidateAccessTokenPolicy", validateAccessTokenPolicy => - { - // Validate id of application for which the token was created - // In this case the UI application - validateAccessTokenPolicy.RequireClaim("azp", "2b50a014-f353-4c10-aace-024f19a55569"); - - // only allow tokens which used "Private key JWT Client authentication" - // // https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens - // Indicates how the client was authenticated. For a public client, the value is "0". - // If client ID and client secret are used, the value is "1". - // If a client certificate was used for authentication, the value is "2". - validateAccessTokenPolicy.RequireClaim("azpacr", "1"); - }); -}); - -builder.Services.AddSwaggerGen(c => -{ - // add JWT Authentication - var securityScheme = new OpenApiSecurityScheme - { - Name = "JWT Authentication", - Description = "Enter JWT Bearer token **_only_**", - In = ParameterLocation.Header, - Type = SecuritySchemeType.Http, - Scheme = "bearer", // must be lower case - BearerFormat = "JWT", - Reference = new OpenApiReference - { - Id = JwtBearerDefaults.AuthenticationScheme, - Type = ReferenceType.SecurityScheme - } - }; - c.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme); - c.AddSecurityRequirement(new OpenApiSecurityRequirement - { - {securityScheme, Array.Empty()} - }); - - c.SwaggerDoc("v1", new OpenApiInfo - { - Title = "User API One", - Version = "v1", - Description = "User API One", - Contact = new OpenApiContact - { - Name = "damienbod", - Email = string.Empty, - Url = new Uri("https://damienbod.com/"), - }, - }); -}); - -var app = builder.Build(); - -JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); -IdentityModelEventSource.ShowPII = true; -JwtSecurityTokenHandler.DefaultMapInboundClaims = false; - -if (app.Environment.IsDevelopment()) -{ - app.UseDeveloperExceptionPage(); -} - -app.UseSwagger(); -app.UseSwaggerUI(c => -{ - c.SwaggerEndpoint("/swagger/v1/swagger.json", "User API One"); - c.RoutePrefix = string.Empty; -}); - -app.UseHttpsRedirection(); - -app.UseRouting(); - -app.UseAuthentication(); -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.Authorization; +using Microsoft.Identity.Web; +using Microsoft.IdentityModel.Logging; +using Microsoft.OpenApi.Models; +using System.IdentityModel.Tokens.Jwt; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services + .AddMicrosoftIdentityWebApiAuthentication(builder.Configuration); + +builder.Services.AddControllers(options => +{ + var policy = new AuthorizationPolicyBuilder() + .RequireAuthenticatedUser() + .Build(); + options.Filters.Add(new AuthorizeFilter(policy)); +}); + +builder.Services.AddAuthorization(options => +{ + options.AddPolicy("ValidateAccessTokenPolicy", validateAccessTokenPolicy => + { + // Validate id of application for which the token was created + // In this case the UI application + validateAccessTokenPolicy.RequireClaim("azp", "2b50a014-f353-4c10-aace-024f19a55569"); + + // only allow tokens which used "Private key JWT Client authentication" + // // https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens + // Indicates how the client was authenticated. For a public client, the value is "0". + // If client ID and client secret are used, the value is "1". + // If a client certificate was used for authentication, the value is "2". + validateAccessTokenPolicy.RequireClaim("azpacr", "1"); + }); +}); + +builder.Services.AddSwaggerGen(c => +{ + // add JWT Authentication + var securityScheme = new OpenApiSecurityScheme + { + Name = "JWT Authentication", + Description = "Enter JWT Bearer token **_only_**", + In = ParameterLocation.Header, + Type = SecuritySchemeType.Http, + Scheme = "bearer", // must be lower case + BearerFormat = "JWT", + Reference = new OpenApiReference + { + Id = JwtBearerDefaults.AuthenticationScheme, + Type = ReferenceType.SecurityScheme + } + }; + c.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + {securityScheme, Array.Empty()} + }); + + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "User API One", + Version = "v1", + Description = "User API One", + Contact = new OpenApiContact + { + Name = "damienbod", + Email = string.Empty, + Url = new Uri("https://damienbod.com/"), + }, + }); +}); + +var app = builder.Build(); + +JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); +IdentityModelEventSource.ShowPII = true; +JwtSecurityTokenHandler.DefaultMapInboundClaims = false; + +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} + +app.UseSwagger(); +app.UseSwaggerUI(c => +{ + c.SwaggerEndpoint("/swagger/v1/swagger.json", "User API One"); + c.RoutePrefix = string.Empty; +}); + +app.UseHttpsRedirection(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/AngularAzureADMultipleApis/UserApi/Properties/launchSettings.json b/AngularMicrsoftEntraIDMultipleApis/UserApi/Properties/launchSettings.json similarity index 95% rename from AngularAzureADMultipleApis/UserApi/Properties/launchSettings.json rename to AngularMicrsoftEntraIDMultipleApis/UserApi/Properties/launchSettings.json index 5f49d19..9a363c9 100644 --- a/AngularAzureADMultipleApis/UserApi/Properties/launchSettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/Properties/launchSettings.json @@ -1,13 +1,13 @@ -{ - "profiles": { - "UserApi": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:44395" - } - } +{ + "profiles": { + "UserApi": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:44395" + } + } } \ No newline at end of file diff --git a/AngularAzureADMultipleApis/UserApi/UserApi.csproj b/AngularMicrsoftEntraIDMultipleApis/UserApi/UserApi.csproj similarity index 96% rename from AngularAzureADMultipleApis/UserApi/UserApi.csproj rename to AngularMicrsoftEntraIDMultipleApis/UserApi/UserApi.csproj index 7071290..82a411a 100644 --- a/AngularAzureADMultipleApis/UserApi/UserApi.csproj +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/UserApi.csproj @@ -1,15 +1,15 @@ - - - - net8.0 - aspnet-UserApiOne-2ba0bbf9-49f5-452e-8333-1e33a467b74e - enable - enable - - - - - - - - + + + + net8.0 + aspnet-UserApiOne-2ba0bbf9-49f5-452e-8333-1e33a467b74e + enable + enable + + + + + + + + diff --git a/AngularAzureADMultipleApis/UserApi/appsettings.Development.json b/AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.Development.json similarity index 98% rename from AngularAzureADMultipleApis/UserApi/appsettings.Development.json rename to AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.Development.json index dba68eb..8983e0f 100644 --- a/AngularAzureADMultipleApis/UserApi/appsettings.Development.json +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.Development.json @@ -1,9 +1,9 @@ { "Logging": { "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } } } diff --git a/AngularAzureADMultipleApis/UserApi/appsettings.json b/AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.json similarity index 96% rename from AngularAzureADMultipleApis/UserApi/appsettings.json rename to AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.json index 5dc9078..091bdcd 100644 --- a/AngularAzureADMultipleApis/UserApi/appsettings.json +++ b/AngularMicrsoftEntraIDMultipleApis/UserApi/appsettings.json @@ -1,16 +1,16 @@ -{ - "AzureAd": { - "Instance": "https://login.microsoftonline.com/", - "Domain": "damienbodhotmail.onmicrosoft.com", - "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", - "ClientId": "b2a09168-54e2-4bc4-af92-a710a64ef1fa" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} +{ + "AzureAd": { + "Instance": "https://login.microsoftonline.com/", + "Domain": "damienbodhotmail.onmicrosoft.com", + "TenantId": "7ff95b15-dc21-4ba6-bc92-824856578fc1", + "ClientId": "b2a09168-54e2-4bc4-af92-a710a64ef1fa" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}