/// <summary>
 /// Sequence:
 /// -->Retrieve the Request token
 /// -->Retrieve the value from query string
 /// -->Retrieve acces token
 /// -->Retrieve acces secret
 /// -->Redirect to close
 /// </summary>
 /// <returns></returns>
 public ActionResult Response()
 {
     oAuthorizationDB = new OAuthTokens();
     oAuthService = new OAuthService(oAuthorizationdto);
     oAuthorizationdto = oAuthService.GetRequestToken(this);
     if (Request.QueryString.HasKeys())
     {
         oAuthorizationdto.OauthVerifyer = Request.QueryString["oauth_verifier"].ToString();
         oAuthorizationDB.realmid = Convert.ToInt32(Request.QueryString["realmId"].ToString());
         oAuthorizationdto.Realmid = oAuthorizationDB.realmid;
         oAuthorizationDB.datasource = Request.QueryString["dataSource"].ToString();
         oAuthorizationdto.DataSource = oAuthorizationDB.datasource;
         oAuthorizationdto = oAuthService.GetAccessTokenFromServer(this,oAuthorizationdto);
         //encrypt the tokens
         oAuthorizationDB.access_secret = Utility.Encrypt(oAuthorizationdto.AccessTokenSecret, oAuthorizationdto.SecurityKey);
         oAuthorizationDB.access_token = Utility.Encrypt(oAuthorizationdto.AccessToken, oAuthorizationdto.SecurityKey);
         using (var oAuthorizationDBContext = new OAuthdataContext("DBContext"))
         {
             //store the encrypted tokens to DB.
             oAuthorizationDBContext.Tokens.Add(oAuthorizationDB);
             oAuthorizationDBContext.SaveChanges();
         }
     }
     return RedirectToAction("Close", "Home");
 }
コード例 #2
0
 /// <summary>
 /// This function checks whether the token is present.
 /// </summary>
 /// <param name="oauthController"></param>
 /// <returns></returns>
 public OAuthorizationdto IsTokenAvailable(object oauthController)
 {
     var oAuthDetails = new OAuthorizationdto();
     using (var db = new OAuthdataContext("DBContext"))
     {
         foreach (var currentIndex in db.Tokens)
         {
             oAuthDetails.Realmid = currentIndex.realmid;
             string testAccesToken = Utility.Decrypt(currentIndex.access_token, oAuthDetails.SecurityKey);
             string testAccesTokenSecret = Utility.Decrypt(currentIndex.access_secret, oAuthDetails.SecurityKey);
             oAuthDetails.AccessToken = testAccesToken;
             oAuthDetails.AccessTokenSecret = testAccesTokenSecret;
             oAuthDetails.IsConnected = true;
             oAuthDetails.DataSource = currentIndex.datasource;
             oAuthRepository.Save(oauthController, oAuthDetails);
         }
     }
     return oAuthDetails;
 }