Support for OAuth2 authentication workflows

2344
1
02-04-2014 12:27 AM
NaomichiKUWAHARA
Esri Contributor
In version 3.2 of the ArcGIS API for Silverlight, OAuth2 authentication workflows is supported.

When executing the authentication in a Silverlight app , it will provide an "openWindow Call Failed" error message.
When using WPF 10.2, OAuth2 authentication window will be displayed.
The function which displays an authentication dialog is provided in JavaScript and Flex API.

- Flex : IdentifyManager
https://developers.arcgis.com/flex/api-reference/com/esri/ags/components/IdentityManager.html
https://developers.arcgis.com/flex/sample-code/portal-signin.htm

- JavaScript : OAuthHelper
https://developers.arcgis.com/javascript/jssamples/portal_oauth_inline.html

I would like to know how to implement OAuth2 authentication workflows.
0 Kudos
1 Reply
NaomichiKUWAHARA
Esri Contributor
I found that it is necessary to use the OAuthAuthorize.Initialize method.
https://developers.arcgis.com/silverlight/api-reference/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Clien...

The part of sample code is below and it works successfully.
However, I don't know whether my implement is right or not, because the online sample is not provided.
Is this code right?

        public MainPage()
        {
            InitializeComponent();

            OAuthAuthorize.Initialize(SERVERURL);
        }

        private void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            var oauthClientInfo = new IdentityManager.OAuthClientInfo();
            oauthClientInfo.OAuthAuthorize = new OAuthAuthorize();
            oauthClientInfo.ClientId = APPID;
            oauthClientInfo.RedirectUri = REDIRECTURL;
            oauthClientInfo.CallbackUrl = CALLBACKURL;

            var svrInfo = new IdentityManager.ServerInfo();
            svrInfo.TokenAuthenticationType = IdentityManager.TokenAuthenticationType.OAuthAuthorizationCode;
            svrInfo.ServerUrl = SERVERURL;
            svrInfo.OAuthClientInfo = oauthClientInfo;

            var svrInfos = new List<IdentityManager.ServerInfo>();
            svrInfos.Add(svrInfo);

            var im = IdentityManager.Current;            
            im.RegisterServers(svrInfos);

            try
            {
                IdentityManager.GenerateTokenOptions options = new IdentityManager.GenerateTokenOptions();
                options.OAuthAuthorize = oauthClientInfo.OAuthAuthorize;
                options.TokenAuthenticationType = IdentityManager.TokenAuthenticationType.OAuthImplicit;

                im.GenerateCredentialAsync(SERVERURL, (credential, error) =>
                {
                    if (error == null && credential != null)
                    {
                        im.AddCredential(credential);
                        this.SignInButton.Visibility = Visibility.Collapsed;
                        this.UserNameTextBlock.Text = credential.UserName;
                        this.UserNameStackPanel.Visibility = Visibility.Visible;
                        this.SignOutButton.Visibility = Visibility.Visible;
                        LoadWebMap(credential);
                    }
                }, options);
                
            }
        }
0 Kudos