* cldr.js:
* Web.config: * ListItem.cs: * styles.json: * globalize.js: * event.js: * Auth.aspx: * Book.aspx: * Login.aspx: * jquery-2.1.4.js: * map-load.gif: * Book.aspx: * Circle.cs: * Auth.aspx: * mapstyle.css: * date.js: * Login.aspx: * mdd_help.htm: * BlogHelper.cs: * fit-bounds.png: * unresolved.js: * jquery-2.1.4.min.js: * mapstyle-ie.css: * FreeDate.cs: * BookEdit.cs: * number.js: * BlogManager.cs: * plural.js: * jquery-2.1.4.min.map: * jquery.googlemaps.js: * supplemental.js: * BlogProvider.cs: * mapstyle.min.css: * pin-pink.png: * message.js: * ChooseADate.aspx: * pin-azure.png: * currency.js: * jquery-2.1.4-vsdoc.js: * pin-green.png: * MarkdownDeepLib.min.js: * flag-azure.png: * flag-green.png: * needle-pink.png: * ChooseADate.aspx: * niddle-green.png: * ChooseCalendar.aspx: * current-location.png: * jquery.googlemaps.min.js: * ErrorMessage.aspx: * ChooseCalendar.aspx: * relative-time.js: * GoogleErrorMessage.aspx: * popup-template-marker.html: * popup-template-circle.html: * popup-template-polygon.html: * popup-template-polyline.html: * popup-template-rectangle.html: * Web.csproj: * YavscModel.csproj: * YavscClient.csproj: * fortune.csproj: * WebControls.csproj: * SalesCatalog.csproj: * ITContentProvider.csproj: * NpgsqlMRPProviders.csproj: * NpgsqlBlogProvider.csproj: * NpgsqlContentProvider.csproj: Moves to Mono framework * NpgsqlCircleProvider.cs: Makes Circles private, or not * OAuth2.cs: * CircleController.cs: * AccountController.cs: * NpgsqlContentProvider.cs: Impacts htmldoc * NpgsqlMembershipProvider.cs: Makes possible to change the UserName * NpgsqlRoleProvider.cs: Drops this SQL code, which is actually maintained in Web/instdbws.sql * PeopleApi.cs: * GoogleController.cs: * PaypalController.cs: Refactoring * Global.asax.cs: Dropped an useless url mapping * MarkdownHelper.cs: Package update * App.master: * NoLogin.master: Site's favicon update * Circles.aspx: TO BE FIXED :-D * UserPost.aspx: Comment only when logged in * instdbws.sql: Circle public * packages.config: package update
This commit is contained in:
parent
cb2d9c5813
commit
87edbaffe5
91 changed files with 496 additions and 26262 deletions
|
|
@ -28,40 +28,10 @@ using System.Web.Profile;
|
|||
using System.Web;
|
||||
using Yavsc.Model;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using Yavsc.Helpers.Google;
|
||||
|
||||
namespace Yavsc.Helpers.Google
|
||||
{
|
||||
/// <summary>
|
||||
/// Google People API.
|
||||
/// </summary>
|
||||
public class PeopleApi: ApiClient
|
||||
{
|
||||
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the People object associated to the given Google Access Token
|
||||
/// </summary>
|
||||
/// <returns>The me.</returns>
|
||||
/// <param name="gat">The Google Access Token object <see cref="AuthToken"/> class.</param>
|
||||
public static People GetMe (AuthToken gat)
|
||||
{
|
||||
People me;
|
||||
DataContractJsonSerializer ppser = new DataContractJsonSerializer (typeof(People));
|
||||
HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me");
|
||||
webreppro.ContentType = "application/http";
|
||||
webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token);
|
||||
webreppro.Method = "GET";
|
||||
using (WebResponse proresp = webreppro.GetResponse ()) {
|
||||
using (Stream prresponseStream = proresp.GetResponseStream ()) {
|
||||
me = (People) ppser.ReadObject (prresponseStream);
|
||||
prresponseStream.Close ();
|
||||
}
|
||||
proresp.Close ();
|
||||
}
|
||||
webreppro.Abort ();
|
||||
return me;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Google O auth2 client.
|
||||
|
|
@ -108,6 +78,7 @@ namespace Yavsc.Helpers.Google
|
|||
CLIENT_ID, RedirectUri, scope, state);
|
||||
GetAuthResponse (bresp, prms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cal authorization.
|
||||
/// </summary>
|
||||
|
|
@ -157,6 +128,7 @@ namespace Yavsc.Helpers.Google
|
|||
HttpUtility.UrlEncode (code));
|
||||
return postdata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Google Authorization token.
|
||||
/// </summary>
|
||||
|
|
@ -188,7 +160,7 @@ namespace Yavsc.Helpers.Google
|
|||
AuthToken gat = null;
|
||||
using (WebResponse response = webreq.GetResponse ()) {
|
||||
using (Stream responseStream = response.GetResponseStream ()) {
|
||||
gat = (AuthToken) new DataContractJsonSerializer(typeof(AuthToken)).ReadObject (responseStream);
|
||||
gat = (AuthToken)new DataContractJsonSerializer (typeof(AuthToken)).ReadObject (responseStream);
|
||||
responseStream.Close ();
|
||||
}
|
||||
response.Close ();
|
||||
|
|
@ -224,6 +196,28 @@ namespace Yavsc.Helpers.Google
|
|||
return code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invalid O auth2 refresh token.
|
||||
/// </summary>
|
||||
public class InvalidOAuth2RefreshToken: Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">Message.</param>
|
||||
public InvalidOAuth2RefreshToken(string message):base(message)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">Message.</param>
|
||||
/// <param name="innerException">Inner exception.</param>
|
||||
public InvalidOAuth2RefreshToken(string message,Exception innerException):base(message,innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets fresh google credential.
|
||||
/// </summary>
|
||||
|
|
@ -235,11 +229,18 @@ namespace Yavsc.Helpers.Google
|
|||
string token_type = (string)pr.GetPropertyValue ("gtokentype");
|
||||
DateTime token_exp = (DateTime)pr.GetPropertyValue ("gtokenexpir");
|
||||
if (token_exp < DateTime.Now) {
|
||||
string refresh_token = (string)pr.GetPropertyValue ("grefreshtoken");
|
||||
AuthToken gat = OAuth2.GetTokenPosting (
|
||||
string.Format ("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}",
|
||||
CLIENT_ID, CLIENT_SECRET, refresh_token));
|
||||
token = gat.access_token;
|
||||
object ort = pr.GetPropertyValue ("grefreshtoken");
|
||||
if (ort == null) {
|
||||
throw new InvalidOAuth2RefreshToken ("Google");
|
||||
}
|
||||
else {
|
||||
string refresh_token = ort as string;
|
||||
|
||||
AuthToken gat = OAuth2.GetTokenPosting (
|
||||
string.Format ("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}",
|
||||
CLIENT_ID, CLIENT_SECRET, refresh_token));
|
||||
token = gat.access_token;
|
||||
}
|
||||
pr.SetPropertyValue ("gtoken", token);
|
||||
pr.Save ();
|
||||
// ASSERT gat.token_type == pr.GetPropertyValue("token_type")
|
||||
|
|
|
|||
68
web/Helpers/Google/PeopleApi.cs
Normal file
68
web/Helpers/Google/PeopleApi.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// PeopleApi.cs
|
||||
//
|
||||
// Author:
|
||||
// Paul Schneider <paul@pschneider.fr>
|
||||
//
|
||||
// Copyright (c) 2015 GNU GPL
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Model.Google;
|
||||
using System.Web.Profile;
|
||||
using System.Web;
|
||||
using Yavsc.Model;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using Yavsc.Helpers.Google;
|
||||
|
||||
namespace Yavsc.Helpers.Google
|
||||
{
|
||||
/// <summary>
|
||||
/// Google People API.
|
||||
/// </summary>
|
||||
public class PeopleApi: ApiClient
|
||||
{
|
||||
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the People object associated to the given Google Access Token
|
||||
/// </summary>
|
||||
/// <returns>The me.</returns>
|
||||
/// <param name="gat">The Google Access Token object <see cref="AuthToken"/> class.</param>
|
||||
public static People GetMe (AuthToken gat)
|
||||
{
|
||||
People me;
|
||||
DataContractJsonSerializer ppser = new DataContractJsonSerializer (typeof(People));
|
||||
HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me");
|
||||
webreppro.ContentType = "application/http";
|
||||
webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token);
|
||||
webreppro.Method = "GET";
|
||||
using (WebResponse proresp = webreppro.GetResponse ()) {
|
||||
using (Stream prresponseStream = proresp.GetResponseStream ()) {
|
||||
me = (People)ppser.ReadObject (prresponseStream);
|
||||
prresponseStream.Close ();
|
||||
}
|
||||
proresp.Close ();
|
||||
}
|
||||
webreppro.Abort ();
|
||||
return me;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue