Skip to content

Commit 56779f6

Browse files
authored
Update authentication call and corrected minor warnings (#1530)
1 parent 7729e88 commit 56779f6

File tree

27 files changed

+27
-93
lines changed

27 files changed

+27
-93
lines changed

src/MAUI/Maui.Samples/Helpers/ArcGISLoginPrompt.cs

-17
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,6 @@ public static void SetChallengeHandler()
7474
AuthenticationManager.Current.OAuthUserConfigurations.Add(userConfig);
7575
AuthenticationManager.Current.OAuthAuthorizeHandler = new OAuthAuthorize();
7676
}
77-
78-
// ChallengeHandler function that will be called whenever access to a secured resource is attempted.
79-
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
80-
{
81-
Credential credential = null;
82-
83-
try
84-
{
85-
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials.
86-
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
87-
}
88-
// OAuth login was canceled, no need to display error to user.
89-
catch (TaskCanceledException) { }
90-
catch (OperationCanceledException) { }
91-
92-
return credential;
93-
}
9477
}
9578

9679
#region IOAuthAuthorizationHandler implementation

src/MAUI/Maui.Samples/Samples/Data/EditBranchVersioning/EditBranchVersioning.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private async Task Initialize()
5050
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
5151
string sampleServer7User = "editor01";
5252
string sampleServer7Pass = "S7#i2LWmYH75";
53-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
53+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
5454
}
5555
catch (Exception ex)
5656
{

src/MAUI/Maui.Samples/Samples/Layers/DisplayFeatureLayers/DisplayFeatureLayers.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private async Task SetServiceFeatureTableFeatureLayer()
103103
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
104104
string sampleServer7User = "viewer01";
105105
string sampleServer7Pass = "I68VGU^nMurF";
106-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
106+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
107107
}
108108
catch (Exception ex)
109109
{

src/MAUI/Maui.Samples/Samples/Layers/DisplaySubtypeFeatureLayer/DisplaySubtypeFeatureLayer.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private async Task Initialize()
5050
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
5151
string sampleServer7User = "viewer01";
5252
string sampleServer7Pass = "I68VGU^nMurF";
53-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
53+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
5454
}
5555
catch (Exception ex)
5656
{

src/MAUI/Maui.Samples/Samples/Scene/FilterFeaturesInScene/FilterFeaturesInScene.xaml.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ private async Task Initialize()
7373
_sceneLayerExtentPolygon = builder.ToGeometry();
7474

7575
// Create the SceneLayerPolygonFilter to later apply to the OSM buildings layer.
76-
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter()
77-
{
78-
SpatialRelationship = SceneLayerPolygonFilterSpatialRelationship.Disjoint
79-
};
80-
_sceneLayerPolygonFilter.Polygons.Add(builder.ToGeometry());
76+
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter(new List<Polygon>() { builder.ToGeometry() }, SceneLayerPolygonFilterSpatialRelationship.Disjoint);
8177

8278
// Create the extent graphic so we can add it later with the detailed buildings scene layer.
8379
var simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 5.0f);

src/MAUI/Maui.Samples/Samples/Security/TokenSecuredChallenge/TokenSecuredChallenge.xaml.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ private async void LoginInfoEntered(object sender, LoginEventArgs e)
121121
CredentialRequestInfo requestInfo = (CredentialRequestInfo)_loginTaskCompletionSrc.Task.AsyncState;
122122

123123
// Create a token credential using the provided username and password.
124-
TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync
124+
AccessTokenCredential userCredentials = await AccessTokenCredential.CreateAsync
125125
(requestInfo.ServiceUri,
126126
e.Username,
127-
e.Password,
128-
requestInfo.GenerateTokenOptions);
127+
e.Password);
129128

130129
// Set the task completion source result with the ArcGIS network credential.
131130
// AuthenticationManager is waiting for this result and will add it to its Credentials collection.

src/MAUI/Maui.Samples/Samples/UtilityNetwork/ConfigureSubnetworkTrace/ConfigureSubnetworkTrace.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private async Task Initialize()
5757
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
5858
string sampleServer7User = "viewer01";
5959
string sampleServer7Pass = "I68VGU^nMurF";
60-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
60+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
6161
}
6262
catch (Exception ex)
6363
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/CreateLoadReport/CreateLoadReport.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private async Task Initialize()
7979
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
8080
string sampleServer7User = "editor01";
8181
string sampleServer7Pass = "S7#i2LWmYH75";
82-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
82+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
8383
}
8484
catch (Exception ex)
8585
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/DisplayUtilityAssociations/DisplayUtilityAssociations.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private async Task Initialize()
6060
string sampleServer7User = "viewer01";
6161
string sampleServer7Pass = "I68VGU^nMurF";
6262

63-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
63+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
6464
}
6565
catch (Exception ex)
6666
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/DisplayUtilityNetworkContainer/DisplayUtilityNetworkContainer.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private async Task Initialize()
5353
string sampleServer7User = "viewer01";
5454
string sampleServer7Pass = "I68VGU^nMurF";
5555

56-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
56+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
5757
}
5858
catch (Exception ex)
5959
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/PerformValveIsolationTrace/PerformValveIsolationTrace.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private async Task Initialize()
6666
string sampleServer7User = "viewer01";
6767
string sampleServer7Pass = "I68VGU^nMurF";
6868

69-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
69+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
7070
}
7171
catch (Exception ex)
7272
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/TraceUtilityNetwork/TraceUtilityNetwork.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private async Task Initialize()
6464
string sampleServer7User = "viewer01";
6565
string sampleServer7Pass = "I68VGU^nMurF";
6666

67-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
67+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
6868
}
6969
catch (Exception ex)
7070
{

src/MAUI/Maui.Samples/Samples/UtilityNetwork/ValidateUtilityNetworkTopology/ValidateUtilityNetworkTopology.xaml.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ private async Task Initialize()
110110
"https://sampleserver7.arcgisonline.com/portal/sharing/rest";
111111
string sampleServer7User = "editor01";
112112
string sampleServer7Pass = "S7#i2LWmYH75";
113-
var credential = await AuthenticationManager
114-
.Current
115-
.GenerateCredentialAsync(
113+
var credential = await AccessTokenCredential.CreateAsync(
116114
new Uri(sampleServerPortalUrl),
117115
sampleServer7User,
118116
sampleServer7Pass

src/WPF/WPF.Viewer/Helpers/ArcGISLoginPrompt.cs

-18
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,6 @@ public static async Task<bool> EnsureAGOLCredentialAsync()
6767
return loggedIn;
6868
}
6969

70-
// ChallengeHandler function that will be called whenever access to a secured resource is attempted
71-
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
72-
{
73-
Credential credential = null;
74-
75-
try
76-
{
77-
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials
78-
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
79-
}
80-
catch (OperationCanceledException)
81-
{
82-
// OAuth login was canceled, no need to display error to user.
83-
}
84-
85-
return credential;
86-
}
87-
8870
public static void SetChallengeHandler()
8971
{
9072
var userConfig = new OAuthUserConfiguration(new Uri(ArcGISOnlineUrl), AppClientId, new Uri(OAuthRedirectUrl));

src/WPF/WPF.Viewer/Samples/Data/EditBranchVersioning/EditBranchVersioning.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private async Task Initialize()
5454
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
5555
string sampleServer7User = "editor01";
5656
string sampleServer7Pass = "S7#i2LWmYH75";
57-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
57+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
5858
}
5959
catch (Exception ex)
6060
{

src/WPF/WPF.Viewer/Samples/Layers/DisplayFeatureLayers/DisplayFeatureLayers.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private async Task SetServiceFeatureTableFeatureLayer()
107107
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
108108
string sampleServer7User = "viewer01";
109109
string sampleServer7Pass = "I68VGU^nMurF";
110-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
110+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
111111
}
112112
catch (Exception ex)
113113
{

src/WPF/WPF.Viewer/Samples/Layers/DisplaySubtypeFeatureLayer/DisplaySubtypeFeatureLayer.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private async Task Initialize()
5252
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
5353
string sampleServer7User = "viewer01";
5454
string sampleServer7Pass = "I68VGU^nMurF";
55-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
55+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
5656
}
5757
catch (Exception ex)
5858
{

src/WPF/WPF.Viewer/Samples/Scene/FilterFeaturesInScene/FilterFeaturesInScene.xaml.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Esri.ArcGISRuntime.Symbology;
1313
using Esri.ArcGISRuntime.UI;
1414
using System;
15+
using System.Collections.Generic;
1516
using System.Linq;
1617
using System.Threading.Tasks;
1718
using System.Windows;
@@ -76,11 +77,7 @@ private async Task Initialize()
7677
_sceneLayerExtentPolygon = builder.ToGeometry();
7778

7879
// Create the SceneLayerPolygonFilter to later apply to the OSM buildings layer.
79-
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter()
80-
{
81-
SpatialRelationship = SceneLayerPolygonFilterSpatialRelationship.Disjoint
82-
};
83-
_sceneLayerPolygonFilter.Polygons.Add(builder.ToGeometry());
80+
_sceneLayerPolygonFilter = new SceneLayerPolygonFilter(new List<Polygon>() { builder.ToGeometry() }, SceneLayerPolygonFilterSpatialRelationship.Disjoint);
8481

8582
// Create the extent graphic so we can add it later with the detailed buildings scene layer.
8683
var simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 5.0f);

src/WPF/WPF.Viewer/Samples/Security/TokenSecuredChallenge/TokenSecuredChallenge.xaml.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ private async void LoginButtonClick(object sender, RoutedEventArgs e)
9696
try
9797
{
9898
// Create a token credential using the provided username and password.
99-
TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync
99+
AccessTokenCredential userCredentials = await AccessTokenCredential.CreateAsync
100100
(new Uri(loginEntry.ServiceUrl),
101101
loginEntry.UserName,
102-
loginEntry.Password,
103-
loginEntry.RequestInfo.GenerateTokenOptions);
102+
loginEntry.Password);
104103

105104
// Set the result on the task completion source.
106105
_loginTaskCompletionSource.TrySetResult(userCredentials);

src/WPF/WPF.Viewer/Samples/UtilityNetwork/ConfigureSubnetworkTrace/ConfigureSubnetworkTrace.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private async Task Initialize()
6767
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
6868
string sampleServer7User = "viewer01";
6969
string sampleServer7Pass = "I68VGU^nMurF";
70-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
70+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
7171
}
7272
catch (Exception ex)
7373
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/CreateLoadReport/CreateLoadReport.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private async Task Initialize()
8484
// WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
8585
string sampleServer7User = "editor01";
8686
string sampleServer7Pass = "S7#i2LWmYH75";
87-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
87+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
8888
}
8989
catch (Exception ex)
9090
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/DisplayUtilityAssociations/DisplayUtilityAssociations.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private async Task Initialize()
6464
string sampleServer7User = "viewer01";
6565
string sampleServer7Pass = "I68VGU^nMurF";
6666

67-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
67+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
6868
}
6969
catch (Exception ex)
7070
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/DisplayUtilityNetworkContainer/DisplayUtilityNetworkContainer.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private async Task Initialize()
5858
string sampleServer7User = "viewer01";
5959
string sampleServer7Pass = "I68VGU^nMurF";
6060

61-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
61+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
6262
}
6363
catch (Exception ex)
6464
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/PerformValveIsolationTrace/PerformValveIsolationTrace.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private async Task Initialize()
7272
string sampleServer7User = "viewer01";
7373
string sampleServer7Pass = "I68VGU^nMurF";
7474

75-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
75+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
7676
}
7777
catch (Exception ex)
7878
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/TraceUtilityNetwork/TraceUtilityNetwork.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private async Task Initialize()
7373
string sampleServer7User = "viewer01";
7474
string sampleServer7Pass = "I68VGU^nMurF";
7575

76-
return await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
76+
return await AccessTokenCredential.CreateAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass);
7777
}
7878
catch (Exception ex)
7979
{

src/WPF/WPF.Viewer/Samples/UtilityNetwork/ValidateUtilityNetworkTopology/ValidateUtilityNetworkTopology.xaml.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ private async Task Initialize()
114114
"https://sampleserver7.arcgisonline.com/portal/sharing/rest";
115115
string sampleServer7User = "editor01";
116116
string sampleServer7Pass = "S7#i2LWmYH75";
117-
var credential = await AuthenticationManager
118-
.Current
119-
.GenerateCredentialAsync(
117+
var credential = await AccessTokenCredential.CreateAsync(
120118
new Uri(sampleServerPortalUrl),
121119
sampleServer7User,
122120
sampleServer7Pass

src/WinUI/ArcGIS.WinUI.Viewer/Helpers/ArcGISLoginPrompt.cs

-18
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,6 @@ public static async Task<bool> EnsureAGOLCredentialAsync()
6868
return loggedIn;
6969
}
7070

71-
// ChallengeHandler function that will be called whenever access to a secured resource is attempted
72-
public static async Task<Credential> PromptCredentialAsync(CredentialRequestInfo info)
73-
{
74-
Credential credential = null;
75-
76-
try
77-
{
78-
// IOAuthAuthorizeHandler will challenge the user for OAuth credentials
79-
credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);
80-
}
81-
catch (OperationCanceledException)
82-
{
83-
// OAuth login was canceled, no need to display error to user.
84-
}
85-
86-
return credential;
87-
}
88-
8971
public static void SetChallengeHandler(UserControl sample)
9072
{
9173
var userConfig = new OAuthUserConfiguration(new Uri(ArcGISOnlineUrl), AppClientId, new Uri(OAuthRedirectUrl));

0 commit comments

Comments
 (0)