Creating a userlogin with token and tokensecret - dropnet

I'm using Dropnet library to communicate with Dropbox.
After I accept the first time that my account allows my APP I save the token and secret forn next time I can process whatever I want without asking the user again.
But after I do this code:
Try
client.UserLogin = New UserLogin()
client.UserLogin.Token = dropboxAtoken
client.UserLogin.Secret = dropboxAsecret
Dim accountInfo As AccountInfo = client.AccountInfo()
' More of my code
Catch ex As DropNet.Exceptions.DropboxException
messagebox.show(ex.Message.ToString)
End Try
I receive this error:
{"error": "Parameter not found: oauth_token"}
Can anyone help please.

You should use the overload on the DropNetClient constructor that takes both API keys and User tokens that way it will get correctly wired up.
Or create the instance of the UserLogin first then set it on the client.
See the code for the setter of that parameter wires it up when setting it:
https://github.com/DropNet/DropNet/blob/master/DropNet/Client/Client.cs#L32

Related

Mpesa object has no attribute 'update'

I would like to update the first item in the database each time a user clicks on a button but I keep getting the error every time, any assistance would be appreciated, below is the snippet.
Mpesa.objects.filter(Paid_user=self.request.user, Completed=False).first().update(Completed=True)
you get first instance from filter result so model instances does not have update method. if you always have first object then instead of doing that, try to use instance save method;
instance = Mpesa.objects.filter(Paid_user=self.request.user, Completed=False).first()
instance.Completed = True
instance.save(update_fields=["Completed"])

Obtaining HIT Id while creating HIT in Amazon Mturk using Boto

I'm working on a project in Amazon Mturk. Im using the Python Boto API .
The boto.connection.create_HIT() method returns an object of ResultSet from which I am trying to get the HIT Id . I also used Response Groups like 'HITDetail', HITAssignmentSummary' and 'HITQuestion' in the Create_HIT().
my_hit = mturk_connection.create_hit(hit_type = my_hit_type,
question = my_question,
max_assignments = 1,
annotation = "An annotation from boto ",
lifetime = 8*60,
response_groups = ['HITDetail','HITQuestion','HITAssignmentSummary'])
But I am not able to find a way to get the HIT Id from what it returns.
Please help me with this.
In the create_HIT (), pass the value of the argument 'response_groups' as 'Minimal'.
Then in your case, use the my_hit[0].HITTypeId
It should work fine now.. :)

Django Next Parameter Redirect - Adding Additional Parameters

I'm trying to add authentication to my webapp. A user begins the authentication process by going to:
/authorization/v1/new?client_id=X&response_type=Y&redirect_uri=Z
If request.user does not exist, I redirect using the following code:
try:
user_identity = Identity.objects.get(user=request.user)
except:
resource = '%s?next=/authorization/v1/new' % settings.LOGIN_URL
return HttpResponseRedirect(resource)
This takes the user to /login/?next=/authorization/v1/new.
The user logs in successfully, and is redirected back to /authorization/v1/new.
However, now I'm missing the required GET parameters client_id, response_type, and redirect_uri, and this causes the authorization endpoint to throw an error for missing required parameters.
What is the best way to capture the initial GET params, pass them through to login, and attach them to the redirection back to the auth endpoint?
I thought about using sessions or modifying the redirect_uri to attach the other params, but I still need to figure out how to capture a single parameter through this process. I'd like to not have to modify the login code, if possible. Any ideas/suggestions greatly appreciated. Thanks!
If you were using Django's built-in #login_required decorator, I believe this would be taken care of for you as of r2954.
Given that you're not, you just need to replicate the same steps. Just set next to the value of the full path (as Django does in #login_required), like so:
from urllib import quote
...
try:
user_identity = Identity.objects.get(user=request.user)
except Identity.DoesNotExist:
return HttpResponseRedirect('%snext=%s' % (settings.LOGIN_URL, quote(request.get_full_path()))
NB I've also changed your code to avoid your Pokémon exception handling ("Gotta catch 'em all!").

Using Fluent NHibernate Persistence Tester Tool with Object that has encrypted Password field

First of all: I am completely new to Fluent and NHibernate.
I have a User object that contains a password field. When setting that field the value gets encrypted. Now I try to use the
new PersistenceSpecification<User>(session)
...
.CheckProperty(p => p.Password, "secret")
...
.VerifyTheMappings();
persistence checker tool. The problem I am facing is the handling of the password field. The debugger told me that the tool calls the Password field setter multiple times. The first time with the cleartext password "secret". The following times with the encrypted versions ending up with encrypting my password multiple times.
Any idea how to cope with this?
EDIT:
NHibernate has to set the password on the user after it loaded it from db and when you use the standard
Map(user => user.Password);
it will use the property to set the db-value
Map(user => user.Password).Access.CamelCaseField(Prefix.Underscore);
prevents this then
A way to solve this is to use a setter method to set your password, for example
public virtual void UpdatePassword(string newPassword)
{
string hashedPassword = HashPassword(newPassword);
_password = hashedPassword;
}
This way your hash/encryption logic is separate from your property setter. In your PersistenceSpecification test you will then be testing the saving/getting of the encrypted text.
If you need to decrypt the password use a getter method to get the decrypted password (the Password property will contain the encrypted text).
public virtual string GetPasswordDecrypted()
{
...
}
As a side note, unless you have a good reason it will be better to hash the password than encrypt it.

Using Zend_Auth in Pimcore

Im new to Pimcore and I'm trying to use Zend Auth with pimcore objects. I assume this is a wise approach and it seems more or less logical to me. I've done the initial setup of the object within pimcore itself. Now I'm trying to work out how to connect it to zend auth, that is, for example when I extend zend auth and have my own login function, how do i check if the login is valid in my object?
Does someone have a guide that I could use on this perhaps? otherwise if someone could point me in the right direction that would be great
Jason
You can follow this guide: http://www.pimcore.org/forum/discussion/419/zend_auth_adapter-for-pimcore-objects , it worked well for me.
UPDATE: The link above has been taken away, so laying out the full answer here:
First, you need to put ObjectAdapter.php in website/lib/Website/Auth/ObjectAdapter.php .
Then, this is how you login your user (use as you prefer, for example in your controller init function):
$authAdapter = new Website_Auth_ObjectAdapter('Object_Users', 'o_key', 'password', '/users/');
// The parameters are 1. object you keep your users in, 2. the field that contains their username (I use o_key which is the name of the object itself, to keep unique usernames without fuzz), and 3. the password field in the user object.
// Setup auth adapter
$authAdapter->setIdentity($username)->setCredential($password);
$auth = Zend_Auth::getInstance();
// Authenticate
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
// Login successful
} else {
// Login failed
}
To check for a login-session, use:
$this->auth = Zend_Auth::getInstance();
if ($this->auth->hasIdentity()) {
// We have a login session (user is logged in)
$userObject = $this->auth->getIdentity();
}
To kill a session:
Zend_Auth::getInstance()->clearIdentity();