WIP booking

* CalAuth.aspx: A view ... still unused

* style.css: css overflow-y auto, the container making it modal has no
  margin.

* GoogleController.cs: Fixes again the calendar usage,
uses Google API key and client credentials found in configuration file

* ApiClient.cs: Google API key and client credentials are now found in
  configuration file

* CalendarApi.cs: Let the controller build the credential string from
  thr profile object.

* OAuth2.cs: The OAuth2 Client only needs a client id and secret

* yavsc.js: Fixes some css flipping

* ValidateAjaxAttribute.cs: A FIXME

* Web.config: Google key, client id and secret come from application
  settings

* Web.csproj: a page in more

* YavscModel.csproj:
* PostInfoByUser.cs:
* PostInfoByTitle.cs:
* BlogEntryCollection.cs: refactoring
This commit is contained in:
Paul Schneider 2015-11-01 23:05:17 +01:00
commit e6c65019b0
16 changed files with 117 additions and 147 deletions

View file

@ -40,16 +40,17 @@ namespace Yavsc.Helpers.Google
/// <summary>
/// The CLIENT Id.
/// </summary>
protected static string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com";
public static string CLIENT_ID { get ; set ; }
/// <summary>
/// The CLIENt SECREt
/// </summary>
protected static string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL";
public static string CLIENT_SECRET { get ; set ; }
/// <summary>
/// The API KEY.
/// </summary>
protected static string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw";
public static string API_KEY { get ; set ; }
/* // to use in descendence
*
protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";

View file

@ -36,8 +36,12 @@ namespace Yavsc.Helpers.Google
/// <summary>
/// Google Calendar API client.
/// </summary>
public class CalendarApi: ApiClient
public class CalendarApi : ApiClient
{
public CalendarApi(string apiKey)
{
API_KEY = apiKey;
}
/// <summary>
/// The get cal list URI.
/// </summary>
@ -87,8 +91,11 @@ namespace Yavsc.Helpers.Google
/// <param name="mindate">Mindate.</param>
/// <param name="maxdate">Maxdate.</param>
/// <param name="upr">Upr.</param>
public CalendarEventList GetCalendar (string calid, DateTime mindate, DateTime maxdate, ProfileBase upr)
public CalendarEventList GetCalendar (string calid, DateTime mindate, DateTime maxdate,string cred)
{
if (string.IsNullOrWhiteSpace (calid))
throw new Exception ("the calendar identifier is not specified");
string uri = string.Format (
getCalEntriesUri, HttpUtility.UrlEncode (calid)) +
string.Format ("?orderBy=startTime&singleEvents=true&timeMin={0}&timeMax={1}&key=" + API_KEY,
@ -96,7 +103,7 @@ namespace Yavsc.Helpers.Google
HttpUtility.UrlEncode (maxdate.ToString (dateFormat) + timeZone));
HttpWebRequest webreq = WebRequest.CreateHttp (uri);
string cred = OAuth2.GetFreshGoogleCredential (upr);
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
webreq.Method = "GET";
webreq.ContentType = "application/http";

View file

@ -36,7 +36,7 @@ namespace Yavsc.Helpers.Google
/// <summary>
/// Google O auth2 client.
/// </summary>
public class OAuth2:ApiClient
public class OAuth2 : ApiClient
{
/// <summary>
/// The URI used to get tokens.
@ -58,9 +58,11 @@ namespace Yavsc.Helpers.Google
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2"/> class.
/// </summary>
/// <param name="redirectUri">Redirect URI.</param>
public OAuth2 (string redirectUri)
public OAuth2 (string redirectUri, string clientId, string clientSecret)
{
RedirectUri = redirectUri;
CLIENT_ID = clientId;
CLIENT_SECRET = clientSecret;
}
/// <summary>
@ -84,12 +86,10 @@ namespace Yavsc.Helpers.Google
/// </summary>
/// <param name="bresp">Bresp.</param>
/// <param name="state">State.</param>
public void GetCalAuth (HttpResponseBase bresp, string state)
public void GetCalendarScope (HttpResponseBase bresp, string state)
{
string scope = string.Join ("%20", scopeOpenid);
scope = string.Join ("%20", scopeCalendar);
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false&access_type=offline",
CLIENT_ID, RedirectUri, scope, state);
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=true&access_type=offline&approval_prompt=force",
CLIENT_ID, RedirectUri, scopeCalendar, state);
GetAuthResponse (bresp, prms);
}
@ -230,16 +230,14 @@ namespace Yavsc.Helpers.Google
DateTime token_exp = (DateTime) pr.GetPropertyValue ("gtokenexpir");
if (token_exp < DateTime.Now) {
object ort = pr.GetPropertyValue ("grefreshtoken");
if (ort == null || ort is DBNull) {
if (ort is DBNull || string.IsNullOrWhiteSpace((string)ort)) {
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;
}
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("gtokentype")