Access to portal using Credentials

1994
2
Jump to solution
10-17-2016 05:35 AM
AntonioFiume
New Contributor III

Dear All,

i'm using the code present in the ArcGIS Runtime SDK for iOS (Quartz Beta) to connect to the portal:

var portal:AGSPortal!

...

       

self.portal = AGSPortal(URL: NSURL(string: "http://www.arcgis.com")!, loginRequired: false)        

self.portal.credential = AGSCredential(user: "username", password: "password")

        

self.portal.loadWithCompletion() {[weak self] (error) in

if error == nil {

  // check the portal item loaded and print the modified date

  if self?.portal.loadStatus == AGSLoadStatus.Loaded {

   let user = self?.portal.user

   print(user?.fullName)

  }

}

}

if i inserts wrong credential, the system shows ever a default popup to insert the credential (see attachment):

Is possible to manage the login error with a custom code?

In the previous SDK was present a portal delegate "didFailToLoadWithError" to manage the error.

In the code present in the example about Quartz SDK, seems that the code "if error..." is not execute because the systems shows the popup attached.

Is possible to hide the default popup how the previous SDK and manage all errors by code?

Thanks in advance!

Tony

 

0 Kudos
1 Solution

Accepted Solutions
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Antonio,

Sounds like you need to take a look about this AGSAuthenticationManager Class Reference 

By default, Runtime iOS SDK will use the default AuthenticationViewController to manager those authentication. Since you mentioned that you need some custom code to handle those wrong credentials, you should utilize this AGSAuthenticationManager class, <AGSAuthenticationManagerDelegate> Protocol Reference 

 var item: AGSPortalItem?
    var itemArray:NSMutableArray? = NSMutableArray()
    var authenticationManager: AGSAuthenticationManager = AGSAuthenticationManager.sharedAuthenticationManager()
    
    var portalItemID = String()
    let portal = AGSPortal(URL: NSURL(string: "http://www.arcgis.com")!, loginRequired: true)
    let map = AGSMap()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.authenticationManager.delegate = self
        self.tags.append("Bingmaps")
        
        self.portal.credential = AGSCredential(user: "***", password: "***")
        
        self.portal.loadWithCompletion { [weak self](error) -> Void in
....
}

    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    didReceiveAuthenticationChallenge challenge: AGSAuthenticationChallenge) {
        print("This will triggered when recevive authentication Challenge")
    }
    
    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    wantsToDismissViewController viewController: UIViewController) {
        print("This will triggered when dismiss the provided view controller ")
    }
    
    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    wantsToShowViewController viewController: UIViewController) {
        print("This will triggered when show the provided view controller")
    }
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Also, feel free to take a look about this github sample: QuartzSecurity: An iOS app demonstrating how to use Quartz runtime security services. 

View solution in original post

2 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Antonio,

Sounds like you need to take a look about this AGSAuthenticationManager Class Reference 

By default, Runtime iOS SDK will use the default AuthenticationViewController to manager those authentication. Since you mentioned that you need some custom code to handle those wrong credentials, you should utilize this AGSAuthenticationManager class, <AGSAuthenticationManagerDelegate> Protocol Reference 

 var item: AGSPortalItem?
    var itemArray:NSMutableArray? = NSMutableArray()
    var authenticationManager: AGSAuthenticationManager = AGSAuthenticationManager.sharedAuthenticationManager()
    
    var portalItemID = String()
    let portal = AGSPortal(URL: NSURL(string: "http://www.arcgis.com")!, loginRequired: true)
    let map = AGSMap()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.authenticationManager.delegate = self
        self.tags.append("Bingmaps")
        
        self.portal.credential = AGSCredential(user: "***", password: "***")
        
        self.portal.loadWithCompletion { [weak self](error) -> Void in
....
}

    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    didReceiveAuthenticationChallenge challenge: AGSAuthenticationChallenge) {
        print("This will triggered when recevive authentication Challenge")
    }
    
    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    wantsToDismissViewController viewController: UIViewController) {
        print("This will triggered when dismiss the provided view controller ")
    }
    
    func authenticationManager(authenticationManager: AGSAuthenticationManager, 
    wantsToShowViewController viewController: UIViewController) {
        print("This will triggered when show the provided view controller")
    }
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Also, feel free to take a look about this github sample: QuartzSecurity: An iOS app demonstrating how to use Quartz runtime security services. 

AntonioFiume
New Contributor III

Really really thanks!!

It would be impossible for me to found this way!

When i inserts the didReceiveAuthenticationChallenge the default login message now is disappear

Please note that i inserts the  challenge.cancel() code in the function to work fine more time usert tried to login with wrong credential:

func authenticationManager(_ authenticationManager: AGSAuthenticationManager,   didReceive challenge: AGSAuthenticationChallenge) {

       //Important to work fine when retry to login more time

        challenge.cancel();

    }

Really thanks again Yue!

0 Kudos