public void TestOAuthDesktopFlow() { using (var flow = new OAuthDesktopFlow()) { var oauthLink = new OAuth2AuthorizeLink(); var token = flow.GetAuthCode(oauthLink.Target, new Uri("http://localhost:9696/")); Thread.Sleep(5000); Assert.NotNull(token); } }
public void CreateOAuthAuthRequest() { var authLink = new OAuth2AuthorizeLink() { AuthorizationServer = new Uri("https://login.live.com/oauth20_authorize.srf"), ClientId = "...", ResponseType = "code", RedirectUri = new Uri("https://login.live.com/oauth20_desktop.srf"), Scope = new[] { "wl.signin", "wl.basic", "wl.skydrive" }, State = "" }; var request = authLink.CreateRequest(); }
//[Fact] public void CreateRequestForAuthCode() { var authLink = new OAuth2AuthorizeLink() { Target = new Uri("https://login.live.com/oauth20_authorize.srf") }; //var req = authLink.CreateRequest( // clientId: "...", // responseType: "code", // redirectUri: new Uri("https://login.live.com/oauth20_desktop.srf"), // scope : new[] { "wl.signin", "wl.basic", "wl.skydrive_update" }, // state : null); // Copy this URI into the browser, sign in, and then copy the auth code from URL in the browser }
public string GetAuthToken() { var redirectUri = "http://localhost:9696/"; var oauthLink = new OAuth2AuthorizeLink(); string authcode; using (var flow = new OAuthDesktopFlow()) { authcode = flow.GetAuthCode(oauthLink.Target, new Uri(redirectUri)); Thread.Sleep(3000); // Let web browser render page } var tokenLink = new OAuth2TokenLink(); var request = tokenLink.BuildRequest(new Dictionary <string, string>() { { "client_id", "1acc6a2e-dd01-49ad-a856-e24789c77529" }, { "client_secret", "42ebcddd-6988-4835-895c-cff19bdbdbe9" }, { "code", authcode }, { "grant_type", "authorization_code" }, { "redirect_uri", redirectUri } }); var response = _httpClient.SendAsync(request).Result; if (response.StatusCode == HttpStatusCode.OK) { var token = OAuth2TokenLink.ParseTokenBody(response.Content.ReadAsStringAsync().Result); return(token.AccessToken); } else { var error = OAuth2TokenLink.ParseErrorBody(response.Content.ReadAsStringAsync().Result); throw new Exception("Failed to obtain token : " + error.ErrorDescription); } }