注销用户 OneDrive API
Sign out a user OneDrive API
我想在 OneDrive API 中注销一个用户,我尝试了 this,我发送了请求:
var client = new RestClient("https://login.live.com/oauth20_logout.srf?client_id=762d0c10-xxxx-xxxx-xxxx-085a4a1743bc&redirect_uri=urn:ietf:wg:oauth:2.0:oob");
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(response.IsSuccessful);
输出:
302
False
我的问题是如何发送注销请求
恐怕你在执行请求之前没有遵守规则:
- 删除任何缓存的 access_token 或 refresh_token 值
之前从 OAuth 流程收到。
- 在您的应用程序中执行任何注销操作(例如,
清理本地状态、删除任何缓存项等)。
只有在之后才能使用url调用授权网络服务:
https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri={redirect-uri}
删除 cookie 后,浏览器将重定向到您提供的重定向 URL。当浏览器加载您的重定向页面时,不会设置身份验证查询字符串参数,您可以推断用户已注销。
OAuth 本质上是无状态的,所以 "sign out" 真的没有什么可说的。当您完成 OAuth 流程时,您会收到一个返回的令牌。该令牌用于在您每次 调用 API 时验证用户 。如果您不在授权 header 中包含令牌,API 将拒绝您的请求。
因此 "sign out",只需从您的应用 memory/storage 中擦除任何存储的访问令牌值,该应用将无法再访问该用户的帐户。
我想在 OneDrive API 中注销一个用户,我尝试了 this,我发送了请求:
var client = new RestClient("https://login.live.com/oauth20_logout.srf?client_id=762d0c10-xxxx-xxxx-xxxx-085a4a1743bc&redirect_uri=urn:ietf:wg:oauth:2.0:oob");
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(response.IsSuccessful);
输出:
302
False
我的问题是如何发送注销请求
恐怕你在执行请求之前没有遵守规则:
- 删除任何缓存的 access_token 或 refresh_token 值 之前从 OAuth 流程收到。
- 在您的应用程序中执行任何注销操作(例如, 清理本地状态、删除任何缓存项等)。
只有在之后才能使用url调用授权网络服务:
https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri={redirect-uri}
删除 cookie 后,浏览器将重定向到您提供的重定向 URL。当浏览器加载您的重定向页面时,不会设置身份验证查询字符串参数,您可以推断用户已注销。
OAuth 本质上是无状态的,所以 "sign out" 真的没有什么可说的。当您完成 OAuth 流程时,您会收到一个返回的令牌。该令牌用于在您每次 调用 API 时验证用户 。如果您不在授权 header 中包含令牌,API 将拒绝您的请求。
因此 "sign out",只需从您的应用 memory/storage 中擦除任何存储的访问令牌值,该应用将无法再访问该用户的帐户。