Add support to request permission for adding moment types

This commit is contained in:
Jerrie Pelser
2014-04-03 15:16:52 +07:00
parent 5d58f2790f
commit f9dd4506ff
3 changed files with 29 additions and 15 deletions

View File

@@ -188,12 +188,14 @@ namespace Owin.Security.Providers.GooglePlus
"&scope=" + Uri.EscapeDataString(scope) +
"&state=" + Uri.EscapeDataString(state);
// Check if offline access was requested
if (Options.RequestOfflineAccess)
authorizationEndpoint += "&access_type=offline";
//"&request_visible_actions=http://schemas.google.com/AddActivity" +
//"&approval_prompt=force" +
//"&include_granted_scopes=true"
;
// Request the moment types
if (Options.MomentTypes.Count > 0)
authorizationEndpoint += String.Format("&request_visible_actions={0}",
String.Join(" ", Options.MomentTypes));
Response.Redirect(authorizationEndpoint);
}

View File

@@ -63,6 +63,12 @@ namespace Owin.Security.Providers.GooglePlus
/// </summary>
public string ClientSecret { get; set; }
/// <summary>
/// The list of moment types which you application wants to write. During authentication this will be passed through via the request_visible_actions parameter.
/// For more information of the moment types you may request, see https://developers.google.com/+/api/moment-types/
/// </summary>
public IList<string> MomentTypes { get; private set; }
/// <summary>
/// Gets or sets the <see cref="IGooglePlusAuthenticationProvider" /> used in the authentication events
/// </summary>
@@ -98,6 +104,7 @@ namespace Owin.Security.Providers.GooglePlus
Caption = Constants.DefaultAuthenticationType;
CallbackPath = new PathString("/signin-googleplus");
AuthenticationMode = AuthenticationMode.Passive;
MomentTypes = new List<string>();
Scope = new List<string>
{
"https://www.googleapis.com/auth/plus.login",

View File

@@ -50,17 +50,22 @@ namespace OwinOAuthProvidersDemo
//app.UseGitHubAuthentication("", "");
var options = new GooglePlusAuthenticationOptions
{
ClientId = "",
ClientSecret = "",
RequestOfflineAccess = true,
Provider = new GooglePlusAuthenticationProvider
{
OnAuthenticated = async context => System.Diagnostics.Debug.WriteLine(String.Format("Refresh Token: {0}", context.RefreshToken))
}
};
app.UseGooglePlusAuthentication(options);
//var options = new GooglePlusAuthenticationOptions
//{
// ClientId = "",
// ClientSecret = "",
// RequestOfflineAccess = true,
// Provider = new GooglePlusAuthenticationProvider
// {
// OnAuthenticated = async context => System.Diagnostics.Debug.WriteLine(String.Format("Refresh Token: {0}", context.RefreshToken))
// }
//};
//options.MomentTypes.Add("http://schemas.google.com/AddActivity");
//options.MomentTypes.Add("http://schemas.google.com/CheckInActivity");
//options.MomentTypes.Add("http://schemas.google.com/BuyActivity");
//app.UseGooglePlusAuthentication(options);
//app.UseOpenIDAuthentication("http://me.yahoo.com/", "Yahoo");