Spotify Redirect 在参数前添加字符
Spotify Redirect adds character before parameters
问题
我目前正在创建一个 ASP.NET 应用程序,让用户在使用 Spotify Web API 之前登录到 Spotify。
调用 API 时,您指定 response_type、client_id、范围、redirect_uri 和状态。当您进行调用时,它会将您重定向到 "redirect_uri",并将用户信息作为 json 中的参数,因为我想使用 WPF Web 浏览器,所以我必须将其添加到我的代码中以允许 IE 查看JSON(更多信息 here)。
private bool SetRegistery()
{
try
{
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64))
{
using (RegistryKey key = hklm.OpenSubKey(@"MIME\Database\Content Type\application/json", true))
{
if (key != null)
{
key.SetValue("CLSID", "{25336920-03F9-11cf-8FD0-00AA00686F13}");
key.SetValue("Encoding", new byte[] { 0x80, 0x00, 0x00, 0x00 });
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
我第一个去的URL是:
重定向 URI 是 http://httpbin.org/get,它只响应传递的 JSON 但是当 spotify API 重定向我时 url 出来:
http://httpbin.org/get#access_token=...&token_type=Bearer&expires_in=3600&state=...
而不是参数之间的 # 它应该是一个 ?,手动更正它给我我需要的结果。
http://httpbin.org/get?access_token=...&token_type=Bearer&expires_in=3600&state=...
Url代
SpotifyAuthentication spotifyAuth = new SpotifyAuthentication();
string scope = "user-read-private user-read-email";
string redirect_uri = "http://httpbin.org/get";
string state = randomString(16);
string url = "https://accounts.spotify.com/authorize";
url += "?response_type=token";
url += "&client_id=" + WebUtility.UrlEncode(spotifyAuth.clientID);
url += "&scope=" + WebUtility.UrlEncode(scope);
url += "&redirect_uri=" + WebUtility.UrlEncode(redirect_uri);
url += "&state=" + WebUtility.UrlEncode(state);
authenticationBrowser.Url = new System.Uri(url);
Debug.WriteLine(new System.Uri(url));
我尝试过的事情
- 当我将 Spotify URL 复制到我的浏览器时,结果相同
这意味着它不在我的客户端,除了我上面的 URL 一代。
- 我曾尝试编辑浏览器的导航事件以在 url 重定向之前对其进行编辑,但由于某种原因该函数未检测到重定向。
您似乎在描述的是来自 Authorisation Guide 的隐式授权流程,其中最终重定向 URL 是一个散列片段 - 用 # 表示而不是查询字符串是 ?反而。这是正确的行为 - 您应该能够通过获取将包含重定向值的 Url.Fragment 值从 WPF Web 浏览器读取这些值,但是如果出现错误或用户拒绝请求,这将是一个查询符合您预期的字符串值。
问题
我目前正在创建一个 ASP.NET 应用程序,让用户在使用 Spotify Web API 之前登录到 Spotify。
调用 API 时,您指定 response_type、client_id、范围、redirect_uri 和状态。当您进行调用时,它会将您重定向到 "redirect_uri",并将用户信息作为 json 中的参数,因为我想使用 WPF Web 浏览器,所以我必须将其添加到我的代码中以允许 IE 查看JSON(更多信息 here)。
private bool SetRegistery()
{
try
{
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64))
{
using (RegistryKey key = hklm.OpenSubKey(@"MIME\Database\Content Type\application/json", true))
{
if (key != null)
{
key.SetValue("CLSID", "{25336920-03F9-11cf-8FD0-00AA00686F13}");
key.SetValue("Encoding", new byte[] { 0x80, 0x00, 0x00, 0x00 });
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
我第一个去的URL是:
重定向 URI 是 http://httpbin.org/get,它只响应传递的 JSON 但是当 spotify API 重定向我时 url 出来:
http://httpbin.org/get#access_token=...&token_type=Bearer&expires_in=3600&state=...
而不是参数之间的 # 它应该是一个 ?,手动更正它给我我需要的结果。
http://httpbin.org/get?access_token=...&token_type=Bearer&expires_in=3600&state=...
Url代
SpotifyAuthentication spotifyAuth = new SpotifyAuthentication();
string scope = "user-read-private user-read-email";
string redirect_uri = "http://httpbin.org/get";
string state = randomString(16);
string url = "https://accounts.spotify.com/authorize";
url += "?response_type=token";
url += "&client_id=" + WebUtility.UrlEncode(spotifyAuth.clientID);
url += "&scope=" + WebUtility.UrlEncode(scope);
url += "&redirect_uri=" + WebUtility.UrlEncode(redirect_uri);
url += "&state=" + WebUtility.UrlEncode(state);
authenticationBrowser.Url = new System.Uri(url);
Debug.WriteLine(new System.Uri(url));
我尝试过的事情
- 当我将 Spotify URL 复制到我的浏览器时,结果相同 这意味着它不在我的客户端,除了我上面的 URL 一代。
- 我曾尝试编辑浏览器的导航事件以在 url 重定向之前对其进行编辑,但由于某种原因该函数未检测到重定向。
您似乎在描述的是来自 Authorisation Guide 的隐式授权流程,其中最终重定向 URL 是一个散列片段 - 用 # 表示而不是查询字符串是 ?反而。这是正确的行为 - 您应该能够通过获取将包含重定向值的 Url.Fragment 值从 WPF Web 浏览器读取这些值,但是如果出现错误或用户拒绝请求,这将是一个查询符合您预期的字符串值。