Select to view content in your preferred language

Angular 19 - Portal Authentication Sample

226
1
11-26-2024 07:03 AM
PierreMasson
Regular Contributor
import { Component, Inject, OnInit, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule, DOCUMENT } from '@angular/common';

import IdentityManager from "@arcgis/core/identity/IdentityManager";
import ServerInfo from "@arcgis/core/identity/ServerInfo";

@Component({
  selector: 'app-home',
  standalone: true,
  imports: [ CommonModule ],
  providers: [ ],
  templateUrl: './home.component.html',
  styleUrl: './home.component.scss',
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    
    var si = new ServerInfo({
      hasPortal: true,
      server: 'http://myportal.mydomain.com/arcgis',
    });
 
    IdentityManager.registerServers([si]);

    IdentityManager.getCredential(environment.portalUrl);

    IdentityManager.checkSignInStatus(si.server + "/sharing")
    .then(() => {
      console.log("checkSignInStatus: User is signed in.");
    })
    .catch(() => { 
      console.error("checkSignInStatus: User not signed in.") 
    });
  }

}

I'm developping an Angular 19 app using @ArcGIS/core && @ArcGIS/map-components and thing are going well. Only thing left to do is the portal authentication (get a token).

Is there a sample somewhere to help me. I find stuff here and there some with deprecated stuff, some in pure JS but I want to do it cleanly with Angular. 

I have tried this but I get this erreor after the build:
Error when evaluating SSR module.. ReferenceError: ResizeObserver is not defined

Can you help with a sample please?

 

import { Component, Inject, OnInit, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule, DOCUMENT } from '@angular/common';

import IdentityManager from "@arcgis/core/identity/IdentityManager";
import ServerInfo from "@arcgis/core/identity/ServerInfo";

@Component({
  selector: 'app-home',
  standalone: true,
  imports: [ CommonModule ],
  providers: [ ],
  templateUrl: './home.component.html',
  styleUrl: './home.component.scss',
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    
    var si = new ServerInfo({
      hasPortal: true,
      server: 'http://myportal.mydomain.com/arcgis',
    });
 
    IdentityManager.getCredential(environment.portalUrl);
    IdentityManager.registerServers([si]);

    IdentityManager.checkSignInStatus(si.server + "/sharing")
    .then(() => {
      console.log("checkSignInStatus: User is signed in.");
    })
    .catch(() => { 
      console.error("checkSignInStatus: User not signed in.") 
    });
  }

}

 

 

0 Kudos
1 Reply
PierreMasson
Regular Contributor

I disabled ssr in my angular.json file and it seems to work.

 "prerender": false,
 "ssr": false

 

0 Kudos