Skip to content

Commit

Permalink
Update authentication call and corrected minor warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
duffh committed Nov 7, 2024
1 parent 7729e88 commit a9c50a7
Show file tree
Hide file tree
Showing 27 changed files with 27 additions and 93 deletions.
17 changes: 0 additions & 17 deletions src/MAUI/Maui.Samples/Helpers/ArcGISLoginPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@ public static void SetChallengeHandler()
AuthenticationManager.Current.OAuthUserConfigurations.Add(userConfig);
AuthenticationManager.Current.OAuthAuthorizeHandler = new OAuthAuthorize();
}

// ChallengeHandler function that will be called whenever access to a secured resource is attempted.
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
{
Credential credential = null;

try
{
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials.
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
}
// OAuth login was canceled, no need to display error to user.
catch (TaskCanceledException) { }
catch (OperationCanceledException) { }

return credential;
}
}

#region IOAuthAuthorizationHandler implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private async Task SetServiceFeatureTableFeatureLayer()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ private async Task Initialize()
_sceneLayerExtentPolygon = builder.ToGeometry();

// Create the SceneLayerPolygonFilter to later apply to the OSM buildings layer.
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter()
{
SpatialRelationship = SceneLayerPolygonFilterSpatialRelationship.Disjoint
};
_sceneLayerPolygonFilter.Polygons.Add(builder.ToGeometry());
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter(new List<Polygon>() { builder.ToGeometry() }, SceneLayerPolygonFilterSpatialRelationship.Disjoint);

// Create the extent graphic so we can add it later with the detailed buildings scene layer.
var simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 5.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ private async void LoginInfoEntered(object sender, LoginEventArgs e)
CredentialRequestInfo requestInfo = (CredentialRequestInfo)_loginTaskCompletionSrc.Task.AsyncState;

// Create a token credential using the provided username and password.
TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync
AccessTokenCredential userCredentials = await AccessTokenCredential.CreateAsync
(requestInfo.ServiceUri,
e.Username,
e.Password,
requestInfo.GenerateTokenOptions);
e.Password);

// Set the task completion source result with the ArcGIS network credential.
// AuthenticationManager is waiting for this result and will add it to its Credentials collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ private async Task Initialize()
"https://sampleserver7.arcgisonline.com/portal/sharing/rest";
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
var credential = await AuthenticationManager
.Current
.GenerateCredentialAsync(
var credential = await AccessTokenCredential.CreateAsync(
new Uri(sampleServerPortalUrl),
sampleServer7User,
sampleServer7Pass
Expand Down
18 changes: 0 additions & 18 deletions src/WPF/WPF.Viewer/Helpers/ArcGISLoginPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ public static async Task<bool> EnsureAGOLCredentialAsync()
return loggedIn;
}

// ChallengeHandler function that will be called whenever access to a secured resource is attempted
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
{
Credential credential = null;

try
{
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
}
catch (OperationCanceledException)
{
// OAuth login was canceled, no need to display error to user.
}

return credential;
}

public static void SetChallengeHandler()
{
var userConfig = new OAuthUserConfiguration(new Uri(ArcGISOnlineUrl), AppClientId, new Uri(OAuthRedirectUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private async Task SetServiceFeatureTableFeatureLayer()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -76,11 +77,7 @@ private async Task Initialize()
_sceneLayerExtentPolygon = builder.ToGeometry();

// Create the SceneLayerPolygonFilter to later apply to the OSM buildings layer.
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter()
{
SpatialRelationship = SceneLayerPolygonFilterSpatialRelationship.Disjoint
};
_sceneLayerPolygonFilter.Polygons.Add(builder.ToGeometry());
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter(new List<Polygon>() { builder.ToGeometry() }, SceneLayerPolygonFilterSpatialRelationship.Disjoint);

// Create the extent graphic so we can add it later with the detailed buildings scene layer.
var simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 5.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ private async void LoginButtonClick(object sender, RoutedEventArgs e)
try
{
// Create a token credential using the provided username and password.
TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync
AccessTokenCredential userCredentials = await AccessTokenCredential.CreateAsync
(new Uri(loginEntry.ServiceUrl),
loginEntry.UserName,
loginEntry.Password,
loginEntry.RequestInfo.GenerateTokenOptions);
loginEntry.Password);

// Set the result on the task completion source.
_loginTaskCompletionSource.TrySetResult(userCredentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private async Task Initialize()
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private async Task Initialize()
string sampleServer7User = "viewer01";
string sampleServer7Pass = "I68VGU^nMurF";

return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ private async Task Initialize()
"https://sampleserver7.arcgisonline.com/portal/sharing/rest";
string sampleServer7User = "editor01";
string sampleServer7Pass = "S7#i2LWmYH75";
var credential = await AuthenticationManager
.Current
.GenerateCredentialAsync(
var credential = await AccessTokenCredential.CreateAsync(
new Uri(sampleServerPortalUrl),
sampleServer7User,
sampleServer7Pass
Expand Down
18 changes: 0 additions & 18 deletions src/WinUI/ArcGIS.WinUI.Viewer/Helpers/ArcGISLoginPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ public static async Task<bool> EnsureAGOLCredentialAsync()
return loggedIn;
}

// ChallengeHandler function that will be called whenever access to a secured resource is attempted
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
{
Credential credential = null;

try
{
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
}
catch (OperationCanceledException)
{
// OAuth login was canceled, no need to display error to user.
}

return credential;
}

public static void SetChallengeHandler(UserControl sample)
{
var userConfig = new OAuthUserConfiguration(new Uri(ArcGISOnlineUrl), AppClientId, new Uri(OAuthRedirectUrl));
Expand Down

0 comments on commit a9c50a7

Please sign in to comment.