{"id":54119,"date":"2020-09-22T08:00:36","date_gmt":"2020-09-22T06:00:36","guid":{"rendered":"https:\/\/code-maze.com\/?p=54119"},"modified":"2021-12-27T13:40:53","modified_gmt":"2021-12-27T12:40:53","slug":"angular-authentication-actions-with-identityserver4","status":"publish","type":"post","link":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/","title":{"rendered":"Angular Authentication Actions with IdentityServer4"},"content":{"rendered":"<p>In <a href=\"https:\/\/code-maze.com\/angular-oauth2-oidc-configuration-identityserver4\" target=\"_blank\" rel=\"noopener noreferrer\">the previous article<\/a>, we have learned how to integrate an Angular application with IdentityServer4 and how to allow communication between these two projects. The configuration is prepared on both sides and as soon as we click the Login button, we get directed to the Login screen on the IDP level. But when we enter valid credentials, we get redirected to the Angular application on the Not Found (404) page. That\u2019s because we didn\u2019t finish the implementation of the Angular authentication actions. So, in this one, we are going to finish the Angular authentication implementation with the Login and Logout actions.<\/p>\n<p>That said, we strongly recommend <a href=\"https:\/\/code-maze.com\/angular-oauth2-oidc-configuration-identityserver4\" target=\"_blank\" rel=\"noopener noreferrer\">reading the previous article<\/a> to keep track of all the things we implemented up until now.<\/p>\n<p>Additionally, if you want to read the <a href=\"https:\/\/code-maze.com\/identityserver-4-series\/\" target=\"_blank\" rel=\"noopener noreferrer\">entire IdentityServer4, OAuth2, and OIDC series<\/a>, feel free to do that and learn a lot more about the application security in ASP.NET Core.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit the <a href=\"https:\/\/github.com\/CodeMazeBlog\/angular-identityserver4\/tree\/angual-authentication-identityserver4\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Angular Authentication with IdentityServer4<\/a> repository.<\/div>\n<p>So, let&#8217;s start.<\/p>\n<h2 id=\"login-functionality\">Completing the Login Functionality in the Angular Authentication Process<\/h2>\n<p>If you inspect our work so far, you will find the code in the <code>AuthService<\/code> class and some modifications in the <code>app.component.ts<\/code> file to check for the authenticated user. This code provides the functionality to navigate to the IDP server and once we enter credentials, to navigate back to the Angular application. But as soon as we navigate back to the Angular application, we need to complete the signin process because we don\u2019t want to navigate the user to the Not Found page. To do that, we have to process the response from the <code>\/authorization<\/code> endpoint and populate the user object with the id and access tokens.<\/p>\n<p>That said, let\u2019s add a new function in the <code>AuthService<\/code> class:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-title=\"\">public finishLogin = (): Promise&lt;User&gt; =&gt; {\r\n  return this._userManager.signinRedirectCallback()\r\n  .then(user =&gt; {\r\n    this._user = user;\r\n    this._loginChangedSubject.next(this.checkUser(user));\r\n    return user;\r\n  })\r\n}\r\n<\/pre><\/p>\n<p>In this function, we call the <code>signinRedirectCallback<\/code> function that processes the response from the <code>\/authorization<\/code> endpoint and returns a promise. From that promise, we extract the user object and populate the <code>_user<\/code> property. Additionally, we call the <code>next<\/code> function from the observable to inform any subscribed component about the Angular authentication state change, and finally, return that user.<\/p>\n<h3>Adding Signin-Redirect-Callback Component<\/h3>\n<p>Now, we have to create the signin component, use this function, and react to the redirect action from the IDP server:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">ng g c signin-redirect-callback --skipTests<\/pre>\n<p>We can remove the HTML and CSS files because we don\u2019t need them, and modify the <code>.ts<\/code> file:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-highlight=\"2-3,7,11,14-17\" data-enlighter-title=\"\">import { Component, OnInit } from &#039;@angular\/core&#039;;\r\nimport { AuthService } from &#039;..\/shared\/services\/auth.service&#039;;\r\nimport { Router } from &#039;@angular\/router&#039;;\r\n\r\n@Component({\r\n  selector: &#039;app-signin-redirect-callback&#039;,\r\n  template: `&lt;div&gt;&lt;\/div&gt;`\r\n})\r\nexport class SigninRedirectCallbackComponent implements OnInit {\r\n\r\n  constructor(private _authService: AuthService, private _router: Router) { }\r\n\r\n  ngOnInit(): void {\r\n    this._authService.finishLogin()\r\n    .then(_ =&gt; {\r\n      this._router.navigate([&#039;\/&#039;], { replaceUrl: true });\r\n    })\r\n  }\r\n}\r\n<\/pre><\/p>\n<p>As you can see, we only have an empty div element for the template part and that\u2019s the reason why we removed the HTML file. Additionally, in the <code>ngOnInit<\/code> function, we call the <code>finishLogin<\/code> function from the <code>AuthService<\/code> and just navigate the user to the home page. We set the <code>replaceUrl<\/code> property to true because we want to remove this component from the navigation stack.<\/p>\n<p>After that, we have to add the route to this component in the <code>app.module.ts<\/code> file:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-highlight=\"4\" data-enlighter-title=\"\">RouterModule.forRoot([\r\n  { path: &#039;home&#039;, component: HomeComponent },\r\n  { path: &#039;company&#039;, loadChildren: () =&gt; import(&#039;.\/company\/company.module&#039;).then(m =&gt; m.CompanyModule) },\r\n  { path: &#039;signin-callback&#039;, component: SigninRedirectCallbackComponent },\r\n  { path: &#039;404&#039;, component : NotFoundComponent},\r\n  { path: &#039;&#039;, redirectTo: &#039;\/home&#039;, pathMatch: &#039;full&#039; },\r\n  { path: &#039;**&#039;, redirectTo: &#039;\/404&#039;, pathMatch: &#039;full&#039;}\r\n])\r\n<\/pre><\/p>\n<p>The value of the path property must match the value we assigned to the <code>redirect_uri<\/code> property of the <code>UserManager<\/code> settings in the <code>AuthService<\/code> class.<\/p>\n<p>Now, we can test this.<\/p>\n<ul>\n<li>Let\u2019s start the IDP server and the Angular application<\/li>\n<li>Once both started, we can click the Login link in the Angular menu<\/li>\n<li>After the Login screen appears, we should enter valid credentials and click the Login button<\/li>\n<li>Soon after, the application navigates us to the Home screen<\/li>\n<\/ul>\n<p>Excellent.<\/p>\n<p>We can check the logs, to verify what happens behind the scenes:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/11-Angular-Authentication-Login-Console-logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-54120\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/11-Angular-Authentication-Login-Console-logs.png\" alt=\"Angular Authentication Login Console logs\" width=\"1017\" height=\"473\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/11-Angular-Authentication-Login-Console-logs.png 1017w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/11-Angular-Authentication-Login-Console-logs-300x140.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/11-Angular-Authentication-Login-Console-logs-768x357.png 768w\" sizes=\"auto, (max-width: 1017px) 100vw, 1017px\" \/><\/a><\/p>\n<p>We can see the request to the <code>\/token<\/code> endpoint that takes place after we finish the login action. Also, we can see the successful token validation and the call towards the <code>\/userinfo<\/code> endpoint. The <code>given_name<\/code> and the <code>family_name<\/code> claims were returned to the client application.<\/p>\n<h2 id=\"logout-functionality\">Adding Logout Functionality to the Angular Authentication Process<\/h2>\n<p>After we log in and land on the Home page, we can still see the Login link on the menu. This is not user-friendly at all, and there is no way to log out from the application (unless we manually clear the site\u2019s data).<\/p>\n<p>To fix this, let\u2019s open the <code>AuthService<\/code> class and add two functions inside:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-title=\"\">public logout = () =&gt; {\r\n  this._userManager.signoutRedirect();\r\n}\r\n\r\npublic finishLogout = () =&gt; {\r\n  this._user = null;\r\n  return this._userManager.signoutRedirectCallback();\r\n}\r\n<\/pre><\/p>\n<p>In the <code>logout<\/code> function, we call the <code>signoutRedirect<\/code> function to redirect the flow to the IDP server to execute the logout action. Additionally, we create the <code>finishLogout<\/code> function, set the <code>_user<\/code> object to null, and call the <code>singoutRedirectCallback<\/code> function to finish the signout process.<\/p>\n<p>Then, let\u2019s navigate to the <code>menu.component.html<\/code> file, modify the Login link, and add the Logout link:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xhtml\" data-enlighter-title=\"\">&lt;section&gt; \r\n  &lt;button *ngIf=&quot;!isUserAuthenticated&quot; class=&quot;btn btn-link&quot; style=&quot;color:gray&quot; (click)=&quot;login()&quot;&gt;Login&lt;\/button&gt;\r\n  &lt;button *ngIf=&quot;isUserAuthenticated&quot; class=&quot;btn btn-link&quot; style=&quot;color:gray&quot; (click)=&quot;logout()&quot;&gt;Logout&lt;\/button&gt; \r\n&lt;\/section&gt;\r\n<\/pre><\/p>\n<p>We also have to modify the <code>menu.component.ts<\/code> file:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-highlight=\"2,7-10,17-19\" data-enlighter-title=\"\">export class MenuComponent implements OnInit {\r\n  public isUserAuthenticated: boolean = false;\r\n\r\n  constructor(private _authService: AuthService) {}\r\n\r\n  ngOnInit(): void {\r\n    this._authService.loginChanged\r\n    .subscribe(res =&gt; {\r\n      this.isUserAuthenticated = res;\r\n    })\r\n  }\r\n\r\n  public login = () =&gt; {\r\n    this._authService.login();\r\n  }\r\n\r\n  public logout = () =&gt; {\r\n    this._authService.logout();\r\n  }\r\n}\r\n<\/pre><\/p>\n<p>In the <code>ngOnInit<\/code> function, we subscribe to the <code>loginChanged<\/code> observable and set the <code>isUserAuthenticated<\/code> property. This will help our application decide which link to show (Login or Logout). Also, we have the <code>logout<\/code> function that just calls the <code>logout<\/code> function from the <code>AuthService<\/code> class.<\/p>\n<h3>Singout-Redirect-Callback Component Creation<\/h3>\n<p>Now, as we did with the <code>signin-redirect-callback<\/code> component, we are going to create the <code>signout-redirect-callback<\/code> component:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-title=\"\">ng g c signout-redirect-callback --skipTests<\/pre><\/p>\n<p>After the creation, let\u2019s remove the <code>.html<\/code> and <code>.css<\/code> files and modify the <code>.ts<\/code> file:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-highlight=\"2-3,7,11,14-17\" data-enlighter-title=\"\">import { Component, OnInit } from &#039;@angular\/core&#039;;\r\nimport { AuthService } from &#039;..\/shared\/services\/auth.service&#039;;\r\nimport { Router } from &#039;@angular\/router&#039;;\r\n\r\n@Component({\r\n  selector: &#039;app-signout-redirect-callback&#039;,\r\n  template: `&lt;div&gt;&lt;\/div&gt;`\r\n})\r\nexport class SignoutRedirectCallbackComponent implements OnInit {\r\n\r\n  constructor(private _authService: AuthService, private _router: Router) { }\r\n\r\n  ngOnInit(): void {\r\n    this._authService.finishLogout()\r\n    .then(_ =&gt; {\r\n      this._router.navigate([&#039;\/&#039;], { replaceUrl: true });\r\n    })\r\n  }\r\n\r\n}\r\n<\/pre><\/p>\n<p>That\u2019s pretty much it. We just navigate to the home page as soon as this component initializes.<\/p>\n<p>Finally, we have to add the route to this component in the <code>app.module.ts<\/code> file:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-highlight=\"5\" data-enlighter-title=\"\">RouterModule.forRoot([\r\n  { path: &#039;home&#039;, component: HomeComponent },\r\n  { path: &#039;company&#039;, loadChildren: () =&gt; import(&#039;.\/company\/company.module&#039;).then(m =&gt; m.CompanyModule) },\r\n  { path: &#039;signin-callback&#039;, component: SigninRedirectCallbackComponent },\r\n  { path: &#039;signout-callback&#039;, component: SignoutRedirectCallbackComponent },\r\n  { path: &#039;404&#039;, component : NotFoundComponent},\r\n  { path: &#039;&#039;, redirectTo: &#039;\/home&#039;, pathMatch: &#039;full&#039; },\r\n  { path: &#039;**&#039;, redirectTo: &#039;\/404&#039;, pathMatch: &#039;full&#039;}\r\n])\r\n<\/pre><\/p>\n<p>Excellent.<\/p>\n<p>Now, let\u2019s start our applications and login with valid credentials.<\/p>\n<p>Soon after that, the application redirects us to the Home page and the Logout button will appear:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/12-Logout-button-shows-for-the-Angular-Authentication.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-54121\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/12-Logout-button-shows-for-the-Angular-Authentication.png\" alt=\"Logout button shows for the Angular Authentication\" width=\"948\" height=\"180\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/12-Logout-button-shows-for-the-Angular-Authentication.png 948w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/12-Logout-button-shows-for-the-Angular-Authentication-300x57.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/12-Logout-button-shows-for-the-Angular-Authentication-768x146.png 768w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/a><\/p>\n<p>Looks good.<\/p>\n<p>Additionally, if we open the Developer Tools window and navigate to the Application tab, we can find the user object in the Session Storage menu:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/13-Angular-Authentication-Session-Storage-User-Object.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-54122\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/13-Angular-Authentication-Session-Storage-User-Object.png\" alt=\"Angular Authentication Session Storage User Object\" width=\"745\" height=\"264\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/13-Angular-Authentication-Session-Storage-User-Object.png 745w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/13-Angular-Authentication-Session-Storage-User-Object-300x106.png 300w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/a><\/p>\n<p>Finally, let\u2019s click the Logout button.<\/p>\n<p>As soon as we do that, the application redirects us to the IDP level, and then back to the Home page with the Login link displayed. Of course, you can inspect the Session Storage to confirm that the user object is removed.<\/p>\n<h2 id=\"isnepcting-tokens\">Inspecting Tokens<\/h2>\n<p>If we decode the access token, we can see what it consists of:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/14-Access-Token-Decoded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-54123\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/14-Access-Token-Decoded.png\" alt=\"Access Token Decoded\" width=\"423\" height=\"492\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/14-Access-Token-Decoded.png 423w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/14-Access-Token-Decoded-258x300.png 258w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><\/a><\/p>\n<p>We can see the <code>not before (nbf)<\/code> and <code>expiry (exp)<\/code> properties both JSON time stamped. Then, we can see the <code>issuer (iss)<\/code> that points to the IDP server address. Of course, we won\u2019t go through each of them, but you can pay attention to the <code>issuer (iss)<\/code> pointing to the IDP server URI, the <code>audience (aud)<\/code> that has the value of the API scope, <code>client_id<\/code>, the<code> subject identifier (sub)<\/code>, <code>scope<\/code> with all the supported scopes and <code>amr<\/code> (Authentication Methods References) with the password-based authentication (<code>pwd<\/code>) value.<\/p>\n<p>We can also inspect the id_token:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/15-Id-Token-Decoded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-54124\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/15-Id-Token-Decoded.png\" alt=\"Id Token Decoded\" width=\"425\" height=\"388\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/15-Id-Token-Decoded.png 425w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/08\/15-Id-Token-Decoded-300x274.png 300w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/a><\/p>\n<p>Here, we can see many properties we already saw in the access token. Just to mention one thing, this time the audience (aud) property has a value of the client id and not the API scope.<\/p>\n<p>We can extract all this information in our Angular application by using the <code>getUser<\/code> function from the <code>UserManager<\/code> class. If you inspect the <code>isAuthenticated<\/code> function in the <code>AuthService<\/code> class, you can see that the <code>getUser<\/code> function returns a promise with the user object inside. Once we extract that user object, we can access all these properties.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Excellent job.<\/p>\n<p>Now, we know how to create Login action with Angular and IdentityServer4 and what components we require to do so. Similarly, we have learned how to create a Logout action and what components it requires for the redirection purpose. Finally, we have inspected the id token and the access token to verify all the information they consist of.<\/p>\n<p>In the next article, we are going to learn about <a href=\"https:\/\/code-maze.com\/secure-angular-calls-to-webapi-using-access-token\/\" target=\"_blank\" rel=\"noopener noreferrer\">using the access token to secure communication between the Angular application and Web API<\/a>.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article, we have learned how to integrate an Angular application with IdentityServer4 and how to allow communication between these two projects. The configuration is prepared on both sides and as soon as we click the Login button, we get directed to the Login screen on the IDP level. But when we enter [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":55360,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[168,12],"tags":[751,750,752,739,740],"class_list":["post-54119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular","category-csharp","tag-access-token","tag-angular-authentication","tag-id-token","tag-login","tag-logout","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Angular Authentication Actions with IdentityServer4 - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular Authentication Actions with IdentityServer4 - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-22T06:00:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-27T12:40:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"Angular Authentication Actions with IdentityServer4\",\"datePublished\":\"2020-09-22T06:00:36+00:00\",\"dateModified\":\"2021-12-27T12:40:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\"},\"wordCount\":1204,\"commentCount\":14,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png\",\"keywords\":[\"Access Token\",\"Angular Authentication\",\"Id Token\",\"Login\",\"Logout\"],\"articleSection\":[\"Angular\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\",\"url\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\",\"name\":\"Angular Authentication Actions with IdentityServer4 - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png\",\"datePublished\":\"2020-09-22T06:00:36+00:00\",\"dateModified\":\"2021-12-27T12:40:53+00:00\",\"description\":\"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png\",\"width\":1100,\"height\":620,\"caption\":\"Angular Authentication Actions with IdentityServer4\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Angular Authentication Actions with IdentityServer4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular Authentication Actions with IdentityServer4 - Code Maze","description":"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/","og_locale":"en_US","og_type":"article","og_title":"Angular Authentication Actions with IdentityServer4 - Code Maze","og_description":"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.","og_url":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/","og_site_name":"Code Maze","article_published_time":"2020-09-22T06:00:36+00:00","article_modified_time":"2021-12-27T12:40:53+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"Angular Authentication Actions with IdentityServer4","datePublished":"2020-09-22T06:00:36+00:00","dateModified":"2021-12-27T12:40:53+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/"},"wordCount":1204,"commentCount":14,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png","keywords":["Access Token","Angular Authentication","Id Token","Login","Logout"],"articleSection":["Angular","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/","url":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/","name":"Angular Authentication Actions with IdentityServer4 - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png","datePublished":"2020-09-22T06:00:36+00:00","dateModified":"2021-12-27T12:40:53+00:00","description":"In this article, we are going to learn about Angular authentication implementation with the Login and Logout actions, and menu modifications.","breadcrumb":{"@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/09\/Angular-Authentication-Actions-with-IdentityServer4.png","width":1100,"height":620,"caption":"Angular Authentication Actions with IdentityServer4"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/angular-authentication-actions-with-identityserver4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Angular Authentication Actions with IdentityServer4"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/54119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=54119"}],"version-history":[{"count":1,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/54119\/revisions"}],"predecessor-version":[{"id":62220,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/54119\/revisions\/62220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/55360"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=54119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=54119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=54119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}