【问题标题】:Migration of Google Apps Marketplace app to oAuth 2.0 with additional scopes将 Google Apps Marketplace 应用迁移到具有附加范围的 oAuth 2.0
【发布时间】:2014-04-18 07:26:44
【问题描述】:
【问题讨论】:
标签:
google-apps-marketplace
【解决方案1】:
只有域的管理员或用户可以批准其他范围。
域的管理员在升级后会收到一封电子邮件通知。
在您的 oauth2.0 应用程序中,您可以检测是否所有范围都已获得批准。如果没有,您可以向用户显示适当的消息以联系域管理员以批准范围。
【解决方案2】:
为此,我们应该在旧列表和新列表中具有相同的范围。我也面临着将旧用户迁移到新用户的同样问题。请检查下面的代码我是如何从旧用户迁移到新用户的,但是每次我得到 401 UnAuthorized,我可以知道我缺少什么。
String url = String.Format("https://www.googleapis.com/appsmarket/v2/upgradableApp/{0}/{1}/{2}", oldAppId, chromeListing, domain);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "PUT";
request.ContentType = "application/json";
request.Accept = "application/json";
request.ProtocolVersion = HttpVersion.Version11;
request.Credentials = CredentialCache.DefaultCredentials;
request.Headers.Add("Authorization", "OAuth");
Hashtable postObj = new Hashtable();
postObj["Consumer Key"] = oldClientId;
postObj["Consumer Key Secret"] = oldSecret;
String s1 = new JavaScriptSerializer().Serialize(postObj);
var bs = Encoding.UTF8.GetBytes(s1);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
using (WebResponse response = request.GetResponse())
{
using (var sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
}
}