Ejemplo n.º 1
0
 /// <summary>
 /// for access token request
 /// </summary>
 /// <param name="type"></param>
 /// <param name="consumer_key"></param>
 /// <param name="consumer_secret"></param>
 /// <param name="oauth_token"></param>
 /// <param name="oauth_secret"></param>
 /// <param name="oauth_verifier"></param>
 public OAuthClient(OAuthTokenType type, string consumer_key, string consumer_secret, string oauth_token, string oauth_secret, string oauth_verifier, string signature_method, string scope = "")
     : this(type, consumer_key, consumer_secret, "", scope)
 {
     this.oauth_token      = oauth_token;
     this.oauth_secret     = oauth_secret;
     this.oauth_verifier   = oauth_verifier;
     this.signature_method = signature_method;
 }
Ejemplo n.º 2
0
        public oauth_token GetOAuthToken(string oauth_token, OAuthTokenType type)
        {
            var result = db.oauth_tokens.SingleOrDefault(x => x.token_key == oauth_token && x.type == type.ToString());

            DeleteOAuthTokenIfExpired(result);

            return(result);
        }
Ejemplo n.º 3
0
        public oauth_token GetOAuthToken(long subdomainid, string appid, OAuthTokenType type)
        {
            var result = db.oauth_tokens.SingleOrDefault(x => x.subdomainid == subdomainid &&
                                                         x.appid == appid && x.type == type.ToString());

            DeleteOAuthTokenIfExpired(result);

            return(result);
        }
Ejemplo n.º 4
0
 private OAuthClient(OAuthTokenType type, string consumer_key, string consumer_secret, string callback_url = "", string scope = "")
 {
     this.type            = type;
     this.consumer_key    = consumer_key;
     this.consumer_secret = consumer_secret;
     this.callback_url    = callback_url;
     this.scope           = scope;
     parameters           = new NameValueCollection();
 }
Ejemplo n.º 5
0
        private bool saveToken(OAuthTokenType tokenType, string oauth_token, string oauth_verifier)
        {
            using (var repository = new TradelrRepository())
            {
                // oauth_token here would match request token saved in db
                // normally access token is different from request token
                var odb = repository.GetOAuthToken(oauth_token, tokenType);
                if (odb == null)
                {
                    return(false);
                }

                accountHostName = odb.MASTERsubdomain.ToHostName();

                OAuthClient client = null;
                switch (tokenType)
                {
                case OAuthTokenType.YAHOO:
                    client = new OAuthClient(tokenType,
                                             OAuthClient.OAUTH_YAHOO_CONSUMER_KEY,
                                             OAuthClient.OAUTH_YAHOO_CONSUMER_SECRET,
                                             odb.token_key,
                                             odb.token_secret,
                                             oauth_verifier);
                    break;

                case OAuthTokenType.TRADEME:
                    client = new OAuthClient(tokenType, OAuthClient.OAUTH_TRADEME_CONSUMER_KEY,
                                             OAuthClient.OAUTH_TRADEME_CONSUMER_SECRET,
                                             odb.token_key,
                                             odb.token_secret,
                                             oauth_verifier,
                                             "HMAC-SHA1",
                                             "MyTradeMeRead,MyTradeMeWrite");
                    break;

                default:
                    break;
                }

                if (client == null ||
                    !client.GetAccessToken())
                {
                    return(false);
                }

                odb.token_key    = client.oauth_token;
                odb.token_secret = client.oauth_secret;
                odb.guid         = client.guid;
                odb.authorised   = true;
                repository.Save();
            }
            return(true);
        }
Ejemplo n.º 6
0
        public void DeleteOAuthToken(long subdomainid, OAuthTokenType type)
        {
            var oauth =
                db.oauth_tokens.SingleOrDefault(x => x.subdomainid == subdomainid && x.type == type.ToString());

            if (oauth == null)
            {
                Syslog.Write("Can't find {0} token for subdomainid {1}", type, subdomainid);
                return;
            }
            db.oauth_tokens.DeleteOnSubmit(oauth);
            db.SubmitChanges();
        }
Ejemplo n.º 7
0
        public oauth_token GetOAuthToken(long subdomainid, OAuthTokenType type, bool?authorised = null)
        {
            var token = db.oauth_tokens.Where(x => x.subdomainid == subdomainid && x.type == type.ToString());

            if (authorised.HasValue)
            {
                token = token.Where(x => x.authorised == authorised.Value);
            }

            var result = token.SingleOrDefault();

            DeleteOAuthTokenIfExpired(result);

            return(result);
        }
Ejemplo n.º 8
0
        public ActionResult haveToken(OAuthTokenType type)
        {
            var oauth = MASTERdomain.oauth_tokens.SingleOrDefault(x => x.type == type.ToString() && x.authorised);

            if (oauth == null)
            {
                return(Json(false.ToJsonOKData()));
            }

            // check that token has not expired
            if (oauth.expires != null && DateTime.UtcNow > oauth.expires)
            {
                repository.DeleteOAuthToken(subdomainid.Value, type);
                return(Json(false.ToJsonOKData()));
            }

            return(Json(true.ToJsonOKData()));
        }
Ejemplo n.º 9
0
        public static IOAuthAccessToken NewOAuthAccessToken(this IOAuthRemoteServerAccount account, Guid?userId,
                                                            string accessToken, OAuthTokenType tokenType, string refreshToken, string openIdToken,
                                                            string scopes, DateTime retrievedOn, DateTime expiresOn,
                                                            string encryptionChannelName = null)
        {
            var session = EntityHelper.GetSession(account);
            var ent     = session.NewEntity <IOAuthAccessToken>();

            ent.Account     = account;
            ent.UserId      = userId;
            ent.AccessToken = accessToken;
            ent.TokenType   = tokenType;
            if (!string.IsNullOrWhiteSpace(refreshToken))
            {
                ent.RefreshToken = refreshToken;
            }
            //if (!string.IsNullOrWhiteSpace(openIdToken))
            //  ent.OpenIdToken = <Unpack Open Id token>
            ent.Scopes      = scopes;
            ent.RetrievedOn = retrievedOn;
            ent.ExpiresOn   = expiresOn;
            return(ent);
        }
Ejemplo n.º 10
0
 public static IOAuthAccessToken NewOAuthAccessToken(this IOAuthRemoteServerAccount account, Guid? userId, 
     string accessToken, OAuthTokenType tokenType, string refreshToken, string openIdToken,
     string scopes, DateTime retrievedOn, DateTime expiresOn,
     string encryptionChannelName = null)
 {
     var session = EntityHelper.GetSession(account);
       var ent = session.NewEntity<IOAuthAccessToken>();
       ent.Account = account;
       ent.UserId = userId;
       ent.AccessToken = session.NewOrUpdate(ent.AccessToken, accessToken, encryptionChannelName);
       ent.TokenType = tokenType;
       if (!string.IsNullOrWhiteSpace(refreshToken))
     ent.RefreshToken = session.NewOrUpdate(ent.RefreshToken, refreshToken, encryptionChannelName);
       //if (!string.IsNullOrWhiteSpace(openIdToken))
       //  ent.OpenIdToken = <Unpack Open Id token>
       ent.Scopes = scopes;
       ent.RetrievedOn = retrievedOn;
       ent.ExpiresOn = expiresOn;
       return ent;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a token container using specified data.
 /// </summary>
 /// <param name="token">Token.</param>
 /// <param name="secret">Token secret.</param>
 /// <param name="state">Token state.</param>
 public OAuthToken(string token, string secret, OAuthTokenType state)
 {
     Content = token;
     Secret  = secret;
     State   = state;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// for request token request
 /// </summary>
 /// <param name="type"></param>
 /// <param name="consumer_key"></param>
 /// <param name="consumer_secret"></param>
 /// <param name="callback_url"></param>
 /// <param name="signature_method"></param>
 public OAuthClient(OAuthTokenType type, string consumer_key, string consumer_secret, string callback_url = "", string signature_method = "", string scope = "")
     : this(type, consumer_key, consumer_secret, callback_url, scope)
 {
     this.signature_method = signature_method;
 }
Ejemplo n.º 13
0
 public ConsumerToken(IOAuthConsumer ioAuthConsumer, string oauthToken, string oauthTokenSecret, string openId, bool?callbackConfirmed)
     : base(oauthToken, oauthTokenSecret, openId, callbackConfirmed)
 {
     this.CurrentConsumer = ioAuthConsumer;
     this.TokenType       = OAuthTokenType.Unknown;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a token container using specified data.
 /// </summary>
 /// <param name="token">Token.</param>
 /// <param name="secret">Token secret.</param>
 /// <param name="state">Token state.</param>
 public OAuthToken(string token, string secret, OAuthTokenType state)
 {
     Content = token;
     Secret = secret;
     State = state;
 }