public static bool Authenticate( ) { TwitchPassword pt = auth( ); if (pt == null) { Imports.User32.DisplayMessage(IntPtr.Zero, "Couldn't Authenticate!", null, Imports.User32.MessageBoxOptions.Ok | Imports.User32.MessageBoxOptions.IconError); return(false); } else { Console.WriteLine("AccessCode: {0}", pt.access_token); SetToken(pt.access_token); return(true); } }
private static TwitchPassword auth( ) { try { /* * https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=r8829yrhzewp4gwopt9gh90py0s8p3p&redirect_uri=http://integrationservices.blizzeta.net&scope=user_read%20user_blocks_edit%20user_blocks_read%20user_follows_edit%20channel_read%20channel_editor%20channel_commercial%20channel_stream%20channel_subscriptions%20user_subscriptions%20chat_login%20channel_check_subscription */ //Process.Start ( Global.AuthorizationFullPermissions ); string url = ParseAuthorization( ); X509Certificate2 cert = DevDefined.OAuth.Tests.TestCertificates.OAuthTestCertificate( ); OAuthConsumerContext context = new OAuthConsumerContext { ConsumerKey = "api.twitch.tv", SignatureMethod = SignatureMethod.RsaSha1, Key = cert.PrivateKey }; IOAuthSession session = new OAuthSession(context, null, url, null).WithQueryParameters(new { scope = Global.Redirect }); IToken request = session.GetRequestToken( ); string authorize = session.GetUserAuthorizationUrlForToken(request, Global.Redirect); IToken access = session.ExchangeRequestTokenForAccessToken(request); string response = session.Request( ).Get( ).ForUrl(Global.AuthorizationFullPermissions).ToString( ); Console.WriteLine(response); TwitchPassword pt = JsonConvert.DeserializeObject <TwitchPassword> (response); return(pt); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); if (ex.InnerException != null) { Console.WriteLine("Inner Error: {0}", ex.InnerException.Message); } } return(null); }