You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/02/11 22:18:31 UTC
[22/25] incubator-usergrid git commit: fix authentication workflow
fix authentication workflow
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bfdacb34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bfdacb34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bfdacb34
Branch: refs/heads/USERGRID-273
Commit: bfdacb34ebdf918fcf92307c14808cadd5bdd7fd
Parents: 6ba340a
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jan 27 19:31:58 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jan 27 19:31:58 2015 -0700
----------------------------------------------------------------------
.../Usergrid.Notifications/Client/PushClient.cs | 12 +++++++-----
.../Usergrid.Notifications/Client/Usergrid.cs | 10 ++++++----
.../Usergrid.Notifications/MainPage.xaml.cs | 15 ++++++---------
3 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bfdacb34/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
index 8668626..fb8860c 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
@@ -35,12 +35,14 @@ namespace Usergrid.Notifications.Client
private IUsergridHttpClient usergrid;
private ApplicationDataContainer settings;
private PushNotificationChannel channel;
+ private string userId;
- public PushClient(IUsergridHttpClient usergrid, string notifier)
+ public PushClient(IUsergridHttpClient usergrid,string userId, string notifier)
{
this.usergrid = usergrid;
this.settings = ApplicationData.Current.LocalSettings;
this.Notifier = notifier;
+ this.userId = userId;
this.init().ContinueWith(t =>
{
LastException = t.Exception;
@@ -62,7 +64,7 @@ namespace Usergrid.Notifications.Client
payloads.Add(Notifier, payload);
jsonObject.Add("payloads", payloads);
jsonObject.Add("debug", true);
- var jsonResponse = await usergrid.SendAsync(HttpMethod.Post, String.Format("devices/{0}/notifications", this.DeviceId), jsonObject);
+ var jsonResponse = await usergrid.SendAsync(HttpMethod.Post, String.Format("users/{1}/devices/{0}/notifications", this.DeviceId,userId), jsonObject);
return jsonResponse.StatusIsOk;
}
@@ -79,7 +81,7 @@ namespace Usergrid.Notifications.Client
payloads.Add(Notifier, payload);
jsonObject.Add("payloads", payloads);
jsonObject.Add("debug", true);
- var jsonResponse = await usergrid.SendAsync(HttpMethod.Post, String.Format("devices/{0}/notifications", this.DeviceId), jsonObject);
+ var jsonResponse = await usergrid.SendAsync(HttpMethod.Post, String.Format("users/{1}/devices/{0}/notifications", this.DeviceId,userId), jsonObject);
return jsonResponse.StatusIsOk;
}
@@ -114,7 +116,7 @@ namespace Usergrid.Notifications.Client
private async Task<JToken> GetDevice(Guid deviceId)
{
- var jsonResponse = await usergrid.SendAsync(HttpMethod.Get, "devices/" + deviceId, null);
+ var jsonResponse = await usergrid.SendAsync(HttpMethod.Get, "users/"+userId+"/devices/" + deviceId, null);
if (jsonResponse.StatusIsOk)
{
@@ -130,7 +132,7 @@ namespace Usergrid.Notifications.Client
obj.Add(Notifier + ".notifier.id", new JValue(channel.Uri));
var jsonResponse = await usergrid.SendAsync(
(isNew ? HttpMethod.Post : HttpMethod.Put),
- "devices/" + (isNew ? "" : this.DeviceId.ToString()),
+ "users/"+userId+"/devices/" + (isNew ? "" : this.DeviceId.ToString()),
obj
);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bfdacb34/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
index cd0330d..977eb8b 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
@@ -48,13 +48,15 @@ namespace Usergrid.Notifications.Client
/// <param name="org"></param>
/// <param name="app"></param>
/// <param name="channel"></param>
- internal Usergrid(string serverUrl, string org, string app, string notifier)
+ internal Usergrid(string serverUrl, string org, string app, string userId, string password,string notifier)
{
string serverUrlWithSlash = serverUrl.EndsWith("/", StringComparison.CurrentCulture) ? serverUrl : serverUrl + "/";
this.appUrl = String.Format("{0}{1}/{2}/", serverUrlWithSlash, org, app);
this.managementUrl = serverUrlWithSlash + "management/";
this.client = new HttpClient();
- this.push = new PushClient(this,notifier);
+ Authenticate(userId, password, false).ContinueWith(task => {
+ this.push = new PushClient(this, userId, notifier);
+ });
}
public async Task Authenticate(string user, string password, bool isManagement)
@@ -69,7 +71,7 @@ namespace Usergrid.Notifications.Client
if (response.StatusIsOk)
{
this.token = response.GetValue("access_token").Value<String>();
- client.DefaultRequestHeaders.Add("X-Authorization", token);
+ client.DefaultRequestHeaders.Add("Authorization", "Bearer "+ token);
}
else
{
@@ -89,7 +91,7 @@ namespace Usergrid.Notifications.Client
public async Task<EntityResponse> SendAsync(HttpMethod method, string url, object obj, bool useManagementUrl)
{
- HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, (useManagementUrl ? this.managementUrl : this.appUrl) + url);
+ HttpRequestMessage message = new HttpRequestMessage(method, (useManagementUrl ? this.managementUrl : this.appUrl) + url);
if (obj != null)
{
message.Content = getJsonBody(obj);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bfdacb34/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
index 7e03c79..6d4c4ec 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
@@ -44,27 +44,24 @@ namespace Usergrid.Notifications
{
this.InitializeComponent();
//TODO: change me to your server
- serverUrl = "http://10.0.1.20:8080";
+ serverUrl = "https://apigee-internal-prod.mars.apigee.net";
//TODO: change me to your org
- org = "mobile";
+ org = "ugvalidate";
//TODO: change me to your app
app = "sandbox";
//TODO: change me to your notifier name
notifier = "winphone";
//TODO: change me to your user
- user = "superuser";
+ user = "mobileuser";
//TODO: change me to your password
- password = "test";
+ password = "******";
this.NavigationCacheMode = NavigationCacheMode.Required;
- this.setup().ContinueWith(t => {
- LastException = t.Exception;
- });
+ usergrid = new Client.Usergrid(serverUrl, org, app, user, password, notifier);
+
}
private async Task setup()
{
- usergrid = new Client.Usergrid(serverUrl, org, app, notifier);
- await usergrid.Authenticate(user, password, true);
}
/// <summary>