<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: authentication in angular in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206785#M78453</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/176078"&gt;@Mannus_Etten&lt;/a&gt;there are just a couple gotchas in Angular. If you aren't using an oauth popup, make sure you are adding the sign-in divs to your main component's html file. Also make sure to set the redirect_url when you register your app in your Portal (or ArcGIS Online), you may have to experiment with that a bit to get it right for your installation.&amp;nbsp; Here are some example snippets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  @ViewChild('mapViewNode', { static: true }) private mapViewEl!: ElementRef;
  @ViewChild('anonymousPanel', { static: true }) private anonEl!: ElementRef;
  @ViewChild('personalizedPanel', {static: true}) private personalEl!: ElementRef;
  @ViewChild('signIn', {static: true}) private signInEl!: ElementRef;          

  . . . 
  this.anonEl.nativeElement.style.display = "none";
  this.personalEl.nativeElement.style.display = "block";

  this.signInEl.nativeElement.addEventListener("click", () =&amp;gt; {
    // user will be redirected to OAuth Sign In page
    esriId.getCredential(info.portalUrl + "/sharing");
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2022 15:54:20 GMT</pubDate>
    <dc:creator>AndyGup</dc:creator>
    <dc:date>2022-08-26T15:54:20Z</dc:date>
    <item>
      <title>authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206710#M78449</link>
      <description>&lt;P&gt;i find many examples pretty useful but all written with amd / require-syntax.&lt;/P&gt;&lt;P&gt;so also the example with oauth login.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;so in the example there is:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; esriId.registerOAuthInfos([info]);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;but that doesn't work in an angular app with es-modules. How does I do this now?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;HHow do I get the OAuth-popup now?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;i am looking for an example with es-modules. No amd-modules and also no "require(xxxx)"-syntax.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 26 Aug 2022 12:56:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206710#M78449</guid>
      <dc:creator>Mannus_Etten</dc:creator>
      <dc:date>2022-08-26T12:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206750#M78451</link>
      <description>&lt;P&gt;Check this video out. It's all in ESM and can be integrated into Angular projects.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-videos/identitymanager-in-the-arcgis-api-for-javascript/m-p/1191710#M21" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-videos/identitymanager-in-the-arcgis-api-for-javascript/m-p/1191710#M21&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's a blog post on the topic too.&lt;/P&gt;&lt;P&gt;&lt;A href="https://odoe.net/blog/my-secret-arcgis-identity" target="_blank"&gt;https://odoe.net/blog/my-secret-arcgis-identity&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 14:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206750#M78451</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-08-26T14:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206785#M78453</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/176078"&gt;@Mannus_Etten&lt;/a&gt;there are just a couple gotchas in Angular. If you aren't using an oauth popup, make sure you are adding the sign-in divs to your main component's html file. Also make sure to set the redirect_url when you register your app in your Portal (or ArcGIS Online), you may have to experiment with that a bit to get it right for your installation.&amp;nbsp; Here are some example snippets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  @ViewChild('mapViewNode', { static: true }) private mapViewEl!: ElementRef;
  @ViewChild('anonymousPanel', { static: true }) private anonEl!: ElementRef;
  @ViewChild('personalizedPanel', {static: true}) private personalEl!: ElementRef;
  @ViewChild('signIn', {static: true}) private signInEl!: ElementRef;          

  . . . 
  this.anonEl.nativeElement.style.display = "none";
  this.personalEl.nativeElement.style.display = "block";

  this.signInEl.nativeElement.addEventListener("click", () =&amp;gt; {
    // user will be redirected to OAuth Sign In page
    esriId.getCredential(info.portalUrl + "/sharing");
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 15:54:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206785#M78453</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-08-26T15:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206981#M78460</link>
      <description>&lt;P&gt;hi Andy,&lt;/P&gt;&lt;P&gt;i prefer to have the popup-implementation. The popup shows, I can login and then i see in the popup the original angular-app... when i close the popup the console shows me that the login has been canceled &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; I used the oauth-callback.html from the esri resources as callback url in the angular-app&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werkwijze_R_beheerder_0-1661587164644.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49613i172B46EA683BF8E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Werkwijze_R_beheerder_0-1661587164644.png" alt="Werkwijze_R_beheerder_0-1661587164644.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2022 08:00:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1206981#M78460</guid>
      <dc:creator>Werkwijze_R_beheerder</dc:creator>
      <dc:date>2022-08-27T08:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207490#M78488</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/348390"&gt;@Werkwijze_R_beheerder&lt;/a&gt; are you working with &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/176078"&gt;@Mannus_Etten&lt;/a&gt; on the same application? It's a little unclear, and I wanted to make sure the original question got answered, if possible. Your question seems more related to a potential configuration issue.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 23:26:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207490#M78488</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-08-29T23:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207559#M78490</link>
      <description>&lt;P&gt;I logged on to the wrong user to place the previous reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; What kind of configuration can I do to make sure that popup window can be closed and return the login-info and not "login canceled" ?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 05:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207559#M78490</guid>
      <dc:creator>Mannus_Etten</dc:creator>
      <dc:date>2022-08-30T05:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207759#M78504</link>
      <description>&lt;P&gt;Can you clarify what you mean by making sure the login popup can be closed? It should close automatically upon successful login. If a user manually closes the login popup, then it is expected to cancel the login process. That behavior is an industry-standard best practice for all login popups.&lt;/P&gt;&lt;P&gt;Can you provide a simple github repo that reproduces the issue? It's hard to say what's happening without seeing an example since there are a lot of pieces involved in authentication. Have you built a non-Angular, plain JavaScript app that is able to log in, just to verify the login functionality?&lt;/P&gt;&lt;P&gt;One easy thing to check, when getting credentials be sure to set &lt;SPAN&gt;oAuthPopupConfirmation&lt;/SPAN&gt; to false:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;document.getElementById("sign-in").addEventListener("click", () =&amp;gt; {
  // user will be redirected to OAuth sign-in page
  esriId.getCredential((info.portalUrl + "/sharing"), {
    oAuthPopupConfirmation: false
  }).then(function() {
    displayItems();
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 15:58:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207759#M78504</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-08-30T15:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207830#M78507</link>
      <description>&lt;P&gt;i have added you to the repo, thanks already for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 17:57:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1207830#M78507</guid>
      <dc:creator>Mannus_Etten</dc:creator>
      <dc:date>2022-08-30T17:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208442#M78531</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/176078"&gt;@Mannus_Etten&lt;/a&gt; I got it working okay using the inline login pattern. The sample you sent me wasn't working correctly because of how Angular routing works. I think you already suspected that because I saw you started to implement a router.&lt;/P&gt;&lt;P&gt;Here's the example app.component.ts (Angular 13, "@arcgis/core" version 4.24). You'll need to figure out all the CSS and routing, etc that happens after the log in process.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { Component } from '@angular/core';
import OAuthInfo from "@arcgis/core/identity/OAuthInfo";
import esriId from "@arcgis/core/identity/IdentityManager";
import Portal from "@arcgis/core/portal/Portal";
import PortalQueryParams from "@arcgis/core/portal/PortalQueryParams";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Test Login Page';

  private info: OAuthInfo = new OAuthInfo({
    // Swap this ID out with registered application ID
    appId: "YOUR_APPID_GOES_HERE",
    popup: false
  });

  ngOnInit(): void {
    esriId.registerOAuthInfos([this.info]);
    esriId.checkSignInStatus(this.info.portalUrl + "/sharing")
    .then(() =&amp;gt; {
      console.log("checkSignInStatus: User is signed in.");
      this.displayItems();
    })
    .catch(() =&amp;gt; { 
      console.error("checkSignInStatus: User not signed in.") 
    });
  }

  displayItems(): void  {
    const portal = new Portal();
    // Setting authMode to immediate signs the user in once loaded
    portal.authMode = "immediate";
    // Once loaded, user is signed in
    portal.load().then(() =&amp;gt; {
      // Create query parameters for the portal search
      const queryParams = new PortalQueryParams({
        query: "owner:" + portal.user.username,
        sortField: "num-views",
        sortOrder: "desc",
        num: 20
      });
      console.log("User name: ", portal.user.username);
  
      // Query the items based on the queryParams created from portal above
      portal.queryItems(queryParams).then((q) =&amp;gt; {
        console.log("Portal Query results:", q.results);
      });
    });
  }  

  // Call from app.component.html page
  onLogin() {
    esriId.getCredential(this.info.portalUrl + "/sharing");
  }

  // Call from app.component.html page  
  onLogout() {
    esriId.destroyCredentials();
    window.location.reload();
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;And here is the example app.component.html:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!-- app.component.html --&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;button type="submit" (click)="onLogin()"&amp;gt;&amp;lt;b&amp;gt;Login&amp;lt;/b&amp;gt;&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;button type="submit" (click)="onLogout()"&amp;gt;&amp;lt;b&amp;gt;Logout&amp;lt;/b&amp;gt;&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 20:47:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208442#M78531</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-08-31T20:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208556#M78541</link>
      <description>&lt;P&gt;yeah thanks Andy, yesterday I had a look about what happened and the fact that my callback-html was never called did my realize that the routing is probably the issue, the popup is still my preferred way to do it so I have to dive deeper into that&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 05:23:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208556#M78541</guid>
      <dc:creator>Mannus_Etten</dc:creator>
      <dc:date>2022-09-01T05:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: authentication in angular</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208583#M78542</link>
      <description>&lt;P&gt;I got it running in the end, if you place the html in the assets-folder for the oauth-callback it is solved. Files in this folder are not going through the routing mechanism.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 07:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/authentication-in-angular/m-p/1208583#M78542</guid>
      <dc:creator>Mannus_Etten</dc:creator>
      <dc:date>2022-09-01T07:53:37Z</dc:date>
    </item>
  </channel>
</rss>

