public async Task <IEnumerable <string> > Get() { string JIRA_BASE_URL = "https://sprintplanner.atlassian.net"; var config = new TinyOAuthConfig { RequestTokenUrl = JIRA_BASE_URL + "/plugins/servlet/oauth/request-token", AuthorizeTokenUrl = JIRA_BASE_URL + "/plugins/servlet/oauth/authorize", AccessTokenUrl = JIRA_BASE_URL + "/plugins/servlet/oauth/access-token", ConsumerKey = "CONSUMER_KEY", ConsumerSecret = "CONSUMER_SECRET" }; // Use the library var tinyOAuth = new TinyOAuth(config); // Get the request token and request token secret var requestTokenInfo = await tinyOAuth.GetRequestTokenAsync(); // Construct the authorization url var authorizationUrl = tinyOAuth.GetAuthorizationUrl(requestTokenInfo.RequestToken); // *** You will need to implement these methods yourself *** Process.Start(authorizationUrl); //, LaunchUriAsync(new Uri(authorizationUrl)) etc... //var verificationCode = await InputVerificationCodeAsync(authorizationUrl); // *** Important: Do not run this code before visiting and completing the authorization url *** //var accessTokenInfo = await tinyOAuth.GetAccessTokenAsync(requestTokenInfo.RequestToken, requestTokenInfo.RequestTokenSecret, verificationCode); return(new string[] { "value1", "value2" }); }
private HttpWebRequest GenerateRequest(string serviceName, string contentType, System.Net.Http.HttpMethod requestMethod, string Referer = "") { var httpWebRequest = (HttpWebRequest)WebRequest.Create(GetFullServiceName(serviceName)); httpWebRequest.Method = requestMethod.ToString(); httpWebRequest.ContentType = contentType; httpWebRequest.Timeout = RequestTimeOut; var config = new TinyOAuthConfig { ConsumerKey = Authorization.clientId, ConsumerSecret = Authorization.clientSecret }; var tinyOAuth = new TinyOAuth(config); if (serviceName == "/oauth2/token") { httpWebRequest.Headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(Encoding.UTF8.GetBytes(Authorization.clientId + ":" + Authorization.clientSecret))); } else { httpWebRequest.Headers.Add("Authorization", tinyOAuth.GetAuthorizationHeader(Authorization.tokenKey, Authorization.tokenSecret, Regex.Replace(GetFullServiceName(serviceName), "(.*)\\/api(.*)", "$1$2"), requestMethod).ToString()); } httpWebRequest.Referer = Referer; httpWebRequest.UserAgent = "essium-dotnet-connector"; return(httpWebRequest); }
//Very clumsy OAuth implementation. Only provides for 1 user and //requires you run the application several times to complete the process. public async Task GetOAuthSession(TinyOAuthConfig config, TinyOAuth tinyO) { // STEP 1 //Get the request token and request token secret. //Uncomment the 3 lines below //var requestTokenInfo = await tinyO.GetRequestTokenAsync(); //Debug.WriteLine("REQ TOKEN: " + requestTokenInfo.RequestToken); //Debug.WriteLine("REQ TOKEN SECRET: " + requestTokenInfo.RequestTokenSecret); //Construct the authorization url //Uncomment the 2 lines below. //var authorizationUrl = tinyO.GetAuthorizationUrl(requestTokenInfo.RequestToken); //Debug.WriteLine("AUTH URL: " + authorizationUrl); //Stop the program and then comment out the 5 lines again. <-- Important, start over if you forget //From the debug output, copy/paste the request token and request token secret into //the matching parameters below in step 3. //STEP 2 //From the debug output, copy/paste the URL into your browser and approve your product. //The code provided by Hattrick's website is your verifier code to use in step 3. //STEP 3 //Get the access token & secret //Uncomment the 3 lines below. //var accessTokenInfo = await tinyO.GetAccessTokenAsync("your req token", "your req token secret", "your chpp verifier code"); //Debug.WriteLine("ACCESS TOKEN: " + accessTokenInfo.AccessToken); //Debug.WriteLine("ACCESS TOKEN SECRET: " + accessTokenInfo.AccessTokenSecret); //Stop the program again and comment out the 3 lines again. <-- Important, start over if you forget //Finally, copy/paste the access token and the access secret into the variables at the start of this file. //You can also delete the tinyO parameter/variable if you wish. //you can comment out this try/catch if you don't care for the errors you'll get on the //3 steps above, but it's the only code which should remain uncommented when you're done. try { var httpClient = new HttpClient(new TinyOAuthMessageHandler(config, accessToken, accessTokenSecret)); session = httpClient; } catch (Exception e) { //TODO: Write to log file Debug.WriteLine(e.Message); } //Now we just use the HttpClient like normally //To test that your authentication is approved, uncomment the 3 lines below. //If you receive an XML structure with match data you're good to go. //var resp = await session.GetAsync("https://chpp.hattrick.org/chppxml.ashx?file=matchdetails&version=3.0&matchEvents=false&matchID=52282172"); //var respJson = await resp.Content.ReadAsStringAsync(); //Debug.WriteLine("MATCH DETAILS: " + respJson); }
public TelldusClient(string consumerKey, string consumerSecret) { _config = new TinyOAuthConfig { AccessTokenUrl = "https://api.telldus.com/oauth/accessToken", AuthorizeTokenUrl = "https://api.telldus.com/oauth/authorize", RequestTokenUrl = "https://api.telldus.com/oauth/requestToken", ConsumerKey = consumerKey, ConsumerSecret = consumerSecret }; _tinyOAuth = new TinyOAuth(_config); }
/// <summary> /// Get the users access token /// </summary> /// <param name="requestToken"></param> /// <param name="requestTokenSecret"></param> /// <param name="verificationCode"></param> /// <returns></returns> public async Task <AccessTokenInfo> GetAccessToken(string requestToken, string requestTokenSecret, string verificationCode) { // Set up the basic config parameters var config = new TinyOAuthConfig { AccessTokenUrl = AccessTokenUrl, AuthorizeTokenUrl = AuthorizeTokenUrl, RequestTokenUrl = TokenUrl, ConsumerKey = ApiCredentials.ConsumerKey, ConsumerSecret = ApiCredentials.ConsumerSecret }; var tinyOAuth = new TinyOAuth(config); return(await tinyOAuth.GetAccessTokenAsync(requestToken, requestTokenSecret, verificationCode)); }
public ChppAccess() { // Setup basic config var config = new TinyOAuthConfig { AccessTokenUrl = accessUrl, AuthorizeTokenUrl = userAuthorizeUrl, RequestTokenUrl = requestUrl, ConsumerKey = consumerKey, ConsumerSecret = consumerSecret }; // Use the library var tinyO = new TinyOAuth(config); //create the session GetOAuthSession(config, tinyO); }
/// <summary> /// Returns the request token and secret from UpWork /// </summary> /// <returns></returns> public async Task <TokenResponse> GetRequestToken() { TokenResponse tokenResponse = new TokenResponse(); // Set up the basic config parameters var config = new TinyOAuthConfig { AccessTokenUrl = AccessTokenUrl, AuthorizeTokenUrl = AuthorizeTokenUrl, RequestTokenUrl = TokenUrl, ConsumerKey = ApiCredentials.ConsumerKey, ConsumerSecret = ApiCredentials.ConsumerSecret }; // Use the library var tinyOAuth = new TinyOAuth(config); // Get the request token and request token secret tokenResponse.RequestToken = await tinyOAuth.GetRequestTokenAsync(); tokenResponse.AuthorizationUrl = tinyOAuth.GetAuthorizationUrl(tokenResponse.RequestToken.RequestToken + this.GenerateCallback()); return(tokenResponse); }
public OAuth(TinyOAuthConfig config) { _config = config; }