public AuthorizationHeader(ClientCredentials credentials, Nonce nonce, TimeStamp timestamp, Signature signature)
 {
     this.credentials = credentials;
     this.timestamp = timestamp;
     this.nonce = nonce;
     this.signature = signature;
 }
        static void Main(string[] args)
        {
            Uri requestTokenEndPoint = new Uri(REQUEST_TOKEN_END_POINT);
            Uri authorizeEndPoint = new Uri(AUTHORIZE_END_POINT);
            Uri accessTokenEndPoint = new Uri(ACCESS_TOKEN_END_POINT);

            ClientCredentials credentials = new ClientCredentials(CLIENT_IDENTIFIER, CLIENT_SHARED_SECRET);

            try
            {
                NegotiationTokenRequest negotiationTokenRequest = NegotiationTokenRequest.Create(requestTokenEndPoint, credentials);
                NegotiationToken negotiationToken = negotiationTokenRequest.GetToken();

                Console.WriteLine("Negotiation Token: " + negotiationToken.Value);
                Console.WriteLine("Negotiation Token Secret: " + negotiationToken.Secret);

                Uri authorizationUri = AuthorizationUri.Create(authorizeEndPoint, negotiationToken);

                Console.WriteLine(authorizationUri);
                Console.ReadLine(); // Wait for user authorization.

                AccessTokenRequest accessTokenRequest = AccessTokenRequest.Create(accessTokenEndPoint, credentials, negotiationToken);
                AccessToken accessToken = accessTokenRequest.GetToken();

                Console.WriteLine("Access Token: " + accessToken.Value);
                Console.WriteLine("Access Token Secret: " + accessToken.Secret);
            }
            catch (WebException ex)
            {
                Console.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
                Environment.Exit(0);
            }
        }
 protected AccessTokenRequest(Uri requestUri, ClientCredentials credentials, NegotiationToken negociationToken, string verifierCode)
 {
     this.requestUri = requestUri;
     this.clientCredentials = credentials;
     this.negotiationToken = negociationToken;
     this.verifierCode = verifierCode;
 }
 public BaseString(Uri uri, string httpMethod, Nonce nonce, TimeStamp timestamp, ClientCredentials credentials, string type)
 {
     this.uri = uri;
     this.httpMethod = httpMethod;
     this.nonce = nonce;
     this.timestamp = timestamp;
     this.credentials = credentials;
     this.signatureType = type;
 }
        public void WithoutToken()
        {
            ClientCredentials credentials = new ClientCredentials("key", "secret");
            string baseString = "POST&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D6971488%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1327336019%26oauth_version%3D1.0";

            Signature signature = new HmacSha1Signature(baseString.ToString(), credentials);

            Assert.AreEqual("HMAC-SHA1", signature.Method);
            Assert.AreEqual("Qw2B3uOPRWj%2FgzL3jvdwBbkN6zE%3D", signature.Value);
        }
        public void WithoutToken()
        {
            Nonce nonce = new Nonce(4543704);
            TimeStamp timestamp = new TimeStamp("1327332614");
            ClientCredentials credentials = new ClientCredentials(CLIENT_IDENTIFIER, CLIENT_SHARED_SECRET);

            PlainTextSignature signature = new PlainTextSignature(credentials);

            Assert.AreEqual("PLAINTEXT", signature.Method);
            Assert.AreEqual("3nis2ci4qp4zksz&", signature.Value);
        }
        public void WithToken()
        {
            ClientCredentials credentials = new ClientCredentials("key", "secret");
            NegotiationToken token = new NegotiationToken("requestkey", "requestsecret");
            string baseString = "POST&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Faccess_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D6971488%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1327336019%26oauth_token%3Drequestkey%26oauth_version%3D1.0";

            Signature signature = new HmacSha1Signature(baseString, credentials, token);

            Assert.AreEqual("HMAC-SHA1", signature.Method);
            Assert.AreEqual("TtSu4YZhB3uuWPwmCetVARH5f7c%3D", signature.Value);
        }
        public void WithToken()
        {
            Nonce nonce = new Nonce(4543704);
            TimeStamp timestamp = new TimeStamp("1327332614");
            ClientCredentials credentials = new ClientCredentials(CLIENT_IDENTIFIER, CLIENT_SHARED_SECRET);
            AccessToken token = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET); ;

            PlainTextSignature signature = new PlainTextSignature(credentials, token);

            Assert.AreEqual("PLAINTEXT", signature.Method);
            Assert.AreEqual("3nis2ci4qp4zksz&4i5cdsnulour8f5", signature.Value);
        }
        public void RequestWithQueryParameters()
        {
            Nonce nonce = new Nonce("1234");
            TimeStamp timestamp = new TimeStamp("1327772674");
            Uri requestUri = new Uri("http://api.netflix.com/catalog/titles?arg1=value1&arg2=&arg3");
            ClientCredentials credentials = new ClientCredentials("key", "secret");

            BaseString baseString = new BaseString(requestUri, "GET", nonce, timestamp, credentials, HmacSha1Signature.MethodName);

            string expectedBaseString = "GET&http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles&arg1%3Dvalue1%26arg2%3D%26arg3%3D%26oauth_consumer_key%3Dkey%26oauth_nonce%3D1234%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1327772674%26oauth_version%3D1.0";

            Assert.AreEqual(expectedBaseString, baseString.ToString());
        }
        public void RequestOnNonStandardPort()
        {
            Nonce nonce = new Nonce("1234");
            TimeStamp timestamp = new TimeStamp("1327772674");
            Uri requestUri = new Uri("http://api.netflix.com:5050/catalog/titles");
            ClientCredentials credentials = new ClientCredentials("key", "secret");

            BaseString baseString = new BaseString(requestUri, "PUT", nonce, timestamp, credentials, HmacSha1Signature.MethodName);

            string expectedBaseString = "PUT&http%3A%2F%2Fapi.netflix.com%3A5050%2Fcatalog%2Ftitles&oauth_consumer_key%3Dkey%26oauth_nonce%3D1234%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1327772674%26oauth_version%3D1.0";

            Assert.AreEqual(expectedBaseString, baseString.ToString());
        }
 /// <summary>
 /// Creates a PLAINTEXT request authenticator.
 /// </summary>
 /// <param name="credentials">Client credentials</param>
 /// <param name="token">Access token</param>
 /// <returns>PLAINTEXT request authenticator</returns>
 public static RequestAuthenticator GetPlainTextAuthenticator(ClientCredentials credentials, AccessToken token)
 {
     return new PlainTextRequestAuthenticator(credentials, token);
 }
 /// <summary>
 /// Creates an HAMC-SHA1 request authenticator.
 /// </summary>
 /// <param name="credentials">Client credentials</param>
 /// <param name="token">Access token</param>
 /// <returns>HAMC-SHA1 request authenticator</returns>
 public static RequestAuthenticator GetHmacSha1Authenticator(ClientCredentials credentials, AccessToken token)
 {
     return new HmacSha1RequestAuthenticator(credentials, token);
 }
 public RsaSha1RequestAuthenticator(ClientCredentials credentials, AccessToken token, RSAParameters key)
     : base(credentials, token)
 {
     this.key = key;
 }
 public OAuthRequestAuthenticator(ClientCredentials credentials, AccessToken token)
 {
     this.credentials = credentials;
     this.token = token;
 }
 protected NegotiationTokenRequest(Uri requestUri, ClientCredentials credentials)
 {
     this.requestUri = requestUri;
     this.credentials = credentials;
 }
 public HmacSha1Signature(string baseString, ClientCredentials credentials, Token token = null)
 {
     this.baseString  = baseString;
     this.credentials = credentials;
     this.token       = token;
 }
 /// <summary>
 /// Creates a RSA-SHA1 request authenticator.
 /// </summary>
 /// <param name="credentials">Client credentials</param>
 /// <param name="token">Access token</param>
 /// <param name="key">Private key</param>
 /// <returns>RSA-SHA1 request authenticator</returns>
 public static RequestAuthenticator GetRsaSha1Authenticator(ClientCredentials credentials, AccessToken token, RSAParameters key)
 {
     return new RsaSha1RequestAuthenticator(credentials, token, key);
 }
 public BaseString(Uri uri, string httpMethod, Nonce nonce, TimeStamp timestamp, ClientCredentials credentials, string type)
 {
     this.uri           = uri;
     this.httpMethod    = httpMethod;
     this.nonce         = nonce;
     this.timestamp     = timestamp;
     this.credentials   = credentials;
     this.signatureType = type;
 }
 public static AccessTokenRequest Create(Uri requestUri, ClientCredentials credentials, NegotiationToken negociationToken, string verifierCode)
 {
     return new AccessTokenRequest(requestUri, credentials, negociationToken, verifierCode);
 }
 public void Init()
 {
     nonce = new Nonce(int.Parse(NONCE_VALUE));
     timestamp = new TimeStamp(TIMESTAMP_VALUE);
     token = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
     credentials = new ClientCredentials(CLIENT_IDENTIFIER, CLIENT_SHARED_SECRET);
     signature = new PlainTextSignature(credentials, token);
 }
 public static AccessTokenRequest Create(Uri requestUri, ClientCredentials credentials, NegotiationToken negociationToken)
 {
     return new AccessTokenRequest(requestUri, credentials, negociationToken, "");
 }
 public static NegotiationTokenRequest Create(Uri requestUri, ClientCredentials credentials)
 {
     return new NegotiationTokenRequest(requestUri, credentials);
 }
 private string ClientSharedSecret(ClientCredentials credentials)
 {
     return encoder.Encode(credentials.Secret);
 }
 public PlainTextSignature(ClientCredentials credentials, Token token = null)
 {
     this.credentials = credentials;
     this.token = token;
 }
 public HmacSha1RequestAuthenticator(ClientCredentials credentials, AccessToken token)
     : base(credentials, token)
 {
 }
 private string GenerateSignature(ClientCredentials credentials, Token token)
 {
     return String.Join("&", new string[] {
         ClientSharedSecret(credentials),
         TokenSharedSecret(token)
     });
 }
 public void CreateWebRequest()
 {
     credentials = new ClientCredentials("key", "secret");
     accessToken = new AccessToken("token", "secret");
     request = new TestWebRequest("http://www.test.com/");
 }
 public HmacSha1Signature(string baseString, ClientCredentials credentials, Token token = null)
 {
     this.baseString = baseString;
     this.credentials = credentials;
     this.token = token;
 }
 public PlainTextRequestAuthenticator(ClientCredentials credentials, AccessToken token)
     : base(credentials, token)
 {
 }