AnsweredAssumed Answered

Unable to get OAuth to work for portal in QML

Question asked by jr9128 on Aug 15, 2018
Latest reply on Aug 23, 2018 by jr9128

Hello. I have an internally hosted portal and a very basic sample app wherein I am attempting to load a Portal object using OAuth.  I do not want to prompt my user for credentials so I was attempting to do an app logon.  Unfortunately no matter what I do, when I implement the AuthenticationView and check the authentication challenge type it keeps coming back as username/password.  I have gone into the portal and added an "Application" under my account to generate the ID and secret.  I also set that application as public to everyone.  Please help!

 

Here is my sample code...


import QtQuick 2.6
import QtQuick.Controls 1.4
import Esri.ArcGISRuntime 100.2
import Esri.ArcGISRuntime.Toolkit.Dialogs 100.2
import Esri.ArcGISExtras 1.1

 

ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "OAuthTest"
    // add a mapView component
    MapView {
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true
        // add a map to the mapview
        Map {
            // add the BasemapTopographic basemap to the map
            BasemapTopographic {}
        }
    }
    Portal {
        id: onlinePortal
        url: "http://server.company.com/arcgisportal"
        credential: Credential {
            oAuthClientInfo: OAuthClientInfo {
                oAuthMode: Enums.OAuthModeApp
                clientId: "hiddenForForum"
                clientSecret: "hiddenForForum"
            }
        }
        Component.onCompleted: {
            load();
        }
    }
    AuthenticationView {
        anchors.fill: parent
        authenticationManager: AuthenticationManager // set the authenticationManager property
        onAuthChallengeChanged: {
            switch (authChallenge.authenticationChallengeType){
            case Enums.AuthenticationChallengeTypeClientCertificate:
                console.log("we have certificate");
                break;
            case Enums.AuthenticationChallengeTypeSslHandshake:
                console.log("we have handshake");
                break;
            case Enums.AuthenticationChallengeTypeOAuth:
                console.log("we have oauth");
                authChallenge.continueWithOAuthAuthorizationCode(oauthCodeString);
                break;
            case Enums.AuthenticationChallengeTypeUsernamePassword:
                console.log("we have UsernamePassword");
                break;
            default:
                console.log("auth challenge type not recognized");
                authChallenge.
                break;
            }
        }
    }
}

Outcomes