Skip to content

Commit

Permalink
Added token expiration timeout support.
Browse files Browse the repository at this point in the history
Added token expiration timeout support. Commented out service deployment
from CLI demo app.
pheede committed Mar 25, 2013
1 parent 906012b commit 3cb882f
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions ArcGISRESTAdmin/AGSClient.cs
Original file line number Diff line number Diff line change
@@ -70,15 +70,15 @@ public AGSClient(string serverUrl, string username, string password)
/// Authenticate against the defined ArcGIS Server and store the received token for future administrative requests.
/// </summary>
/// <returns></returns>
public async Task Authenticate()
public async Task Authenticate(int? desiredExpiration = null)
{
Uri encryptionInfoEndpoint = new Uri(ServerUrl, "publicKey");
var ei = await GetStringAsync(encryptionInfoEndpoint, addToken: false);

byte[] exponent = EncodingHelper.HexToBytes(ei["publicKey"].Value<string>());
byte[] modulus = EncodingHelper.HexToBytes(ei["modulus"].Value<string>());

string encryptedUsername, encryptedPassword, encryptedClient;
string encryptedUsername, encryptedPassword, encryptedClient, encryptedExpiration = null;

using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512))
{
@@ -88,14 +88,17 @@ public async Task Authenticate()
encryptedUsername = EncodingHelper.BytesToHex(rsa.Encrypt(Encoding.UTF8.GetBytes(Username), false));
encryptedPassword = EncodingHelper.BytesToHex(rsa.Encrypt(Encoding.UTF8.GetBytes(Password), false));
encryptedClient = EncodingHelper.BytesToHex(rsa.Encrypt(Encoding.UTF8.GetBytes("requestip"), false));
if (desiredExpiration != null) encryptedExpiration = EncodingHelper.BytesToHex(rsa.Encrypt(Encoding.UTF8.GetBytes(desiredExpiration.Value.ToString()), false));
}

Uri tokenEndpoint = new Uri(ServerUrl, "generateToken");

var data = new[] { new KeyValuePair<string, string>("username", encryptedUsername),
new KeyValuePair<string, string>("password", encryptedPassword),
new KeyValuePair<string, string>("client", encryptedClient),
new KeyValuePair<string, string>("encrypted", "true") };
var data = new Dictionary<string, string>();
data["username"] = encryptedUsername;
data["password"] = encryptedPassword;
data["client"] = encryptedClient;
if (encryptedExpiration != null) data["expiration"] = encryptedExpiration;
data["encrypted"] = "true";
var content = new FormUrlEncodedContent(data);

var tokenInfo = await PostAsync(tokenEndpoint, content, addToken: false);
4 changes: 2 additions & 2 deletions ArcGISRestCLI/Program.cs
Original file line number Diff line number Diff line change
@@ -71,9 +71,9 @@ static async Task DoWork()

// upload a pre-created .sd to create a new service

Console.Out.WriteLine(@"Uploading C:\Presentations\Demo.sd..");
//Console.Out.WriteLine(@"Uploading C:\Presentations\Demo.sd..");

var publishResponse = await ags.PublishServiceDefinition(new System.IO.FileInfo(@"C:\Presentations\Demo.sd"));
//var publishResponse = await ags.PublishServiceDefinition(new System.IO.FileInfo(@"C:\Presentations\Demo.sd"));
}
}
}

0 comments on commit 3cb882f

Please sign in to comment.