简体   繁体   中英

Sign out a user OneDrive API

I want to sign out a user in OneDrive API, I tried this , I sent the request:

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);

output:

302
False

my question is how to send a logout request

I am afraid you did not follow the rules before performing the request :

  • Delete any cached access_token or refresh_token values you've previously received from the OAuth flow.
  • Perform any sign out actions in your application (for example, cleaning up local state, removing any cached items, etc.).

Only after can you make a call to the authorization web service using the url:

https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri={redirect-uri}

After removing the cookie, the browser will be redirected to the redirect URL you provided. When the browser loads your redirect page, no authentication query string parameters will be set, and you can infer the user has been logged out.

OAuth is inherently stateless so there is really nothing to "sign out" of. When you complete the OAuth flow you receive a token back. That token is used to authenticate the user every time you call the API. If you don't include the token in the Authorization header, the API will reject your request.

So to "sign out", simply wipe any stored access token values from your app's memory/storage and the app will no longer have access to that user's account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM