Keychain for userdata on ios6 - ios6

I have the following code for storing data in the keychain:
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:MounzaKeyName accessGroup:nil];
[keychainItem setObject:txtPassword.text forKey:kSecValueRef];
[keychainItem setObject:txtLogin.text forKey:kSecValueData];
However, whenever I run it, i'm getting the following:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't update the Keychain Item.'
Is there anything I am missing? I tried to investigate this..its happening right after the user is logging in. I'm trying to store the username and password in the code...
Online it was saying that i should be using standard keys, which I am:
Storing keys in KeyChain with KeyChainItemWrapper

You need to use one keychain wrapper per value. You are trying to put two values into one wrapper. Create two wrappers with two different identifiers. In both cases you set a value for the kSecValueData key.

Related

Convert email to username in Jupyterhub from c.AzureAdOAuthenticator.username_claim = 'unique_name'

I am facing a peculiar issue with using Jupyterhub config c.AzureAdOAuthenticator.username_claim = 'unique_name' . Due to the way our AzureAD is configured this returns an email like fname.lname#xyz.com . However we want to convert this to local username fname.lname without the #xyz.com while Spawning jupyterhub-singleuser. Since the enhancement to Refactor oauthenticators #526 is not yet released we cannot use a function like c.AzureAdOAuthenticator.username_claim = 'get_username_from_userinfo' to convert email to username. If we use a mapping like c.AzureAdOAuthenticator.username_map = { 'fname.lname#xyz.com': 'fname.lname'} then it spawns correctly as fname.lname . But we dont want to keep adding these hardcoded maps for any new users added to jupyterhub. How can we handle this issue by changing some code in the jupyterhub version 3.1.0. Which module can we do a small change to remove the domain #xyz.com?
There is a similar issue logged here: https://github.com/jupyterhub/jupyterhub/issues/2579
UPDATE: Below posting is a solution that worked for this issue:
https://discourse.jupyter.org/t/wildcard-mapping-in-azureadoauthenticator-username-map/17686

How I have to get data that store in database and uses in app of flask?

For example I have app on Flask with Postgresql. I have a some TOKENS and KEYS that stored in table companies. I need to get that tokens and keys in different places of my app. What the right way to do that? Any lazy approach?
Now I use app.config (but don't sure about app_context or before_first_request), for example:
with app.app_context():
if current_user:
app.config["CURRENT_COMPANY_ID"] = current_user.company_id
app.config["YANDEX_TOKEN"] =Company.query.filter_by(id=current_user.company_id).one().yandex_disk_token
or that:
with app.app_context():
if current_user:
g.company_id = current_user.company_id
g.yandex_token =Company.query.filter_by(id=current_user.company_id).one().yandex_disk_token
But that approaches sometimes lead to error that caused by current_user is None, or Company is None etc. And I can't recognize where and how I need store and get that TOKENS and KEY so all the users can use it after they are logged but not before that?
Find out:
It needs to update app.config constants before every user's request done. But if the current_user is not allowed (is None) then it will arise error so to make the current_user to not None we must use decorator #login_manager.request_loader
for example that code is placed in __init__ of app folder, and it solve two problems:
no empty current_user before every request we made to database via ORM.
no one request with empty app.config constants.
def set_config():
app.config['CURRENT_COMPANY_ID'] = current_user.company_id
app.config['YANDEX_TOKEN'] = Company.query.filter_by(id=current_user.company_id).first().yandex_disk_token
#login_manager.request_loader
def load_user_from_request(request):
user_id = request.headers.get('User-ID')
if user_id:
return UserModel.query.get(user_id)
return None
#app.before_request
def before_request():
if current_user.is_authenticated:
set_config()

ACAccount Facebook: An active access token must be used to query information about the current user

I am using iOS 6 Social framework for accessing user's Facebook data. I am trying to get likes of the current user within my app using ACAccount and SLRequest. I have a valid Facebook account reference of type ACAccount named facebook, and I'm trying to get user's likes this way:
SLRequest *req = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:url parameters:nil];
req.account = facebook;
[req performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
//my handler code.
}
where url is #"https://graph.facebook.com/me/likes?fields=name"; In my handler, I'm getting this response:
{
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
Shouldn't access tokens be handled by the framework? I've found a similar post Querying Facebook user data through new iOS6 social framework but it doesn't make sense to hard-code an access token parameter into the URL, as logically the access token/login checking should be handled automatically by the framework. In all examples that I've seen around no one plays with an access token manually:
http://damir.me/posts/facebook-authentication-in-ios-6
iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error
etc.
I am using the iOS6-only approach with the built in Social framework, and I'm not using the Facebook SDK. Am I missing something?
Thanks,
Can.
You need to keep a strong reference to the ACAccountStore that the account comes from. If the store gets deallocated, it looks like it causes this problem.
Try running on an actual device instead of a simulator. This worked for me.
Ensure that your bundle id is input into your Facebook app's configuration. You might have a different bundle id for your dev/debug build.

atk4 SQLAuth in Frontend.php

in Frontend.php I replaced this:
$this->add('BasicAuth')
->allow('demo','demo')
// use check() and allowPage for white-list based auth checking
//->check()
;
With this:
$this->add('SQLAuth')->setSource('user','email','password')
// use check() and allowPage for white-list based auth checking
//->check()
;
based on this you tube video: http://www.youtube.com/watch?v=0_OROS53Fq8&feature=relmfu
However, the SQLAuth will not work. I get this error:
Fatal error: Call to a member function loaded() on a non-object in
C:\wamp\www\atk4\lib\Auth\Basic.php on line 242
My table name is correct, and i know the connection is working and there are users in the table, because I built a user registration form and CRUD that works as I walked through the you tube video.
Anybody have an idea what I am doing wrong here?
SQLAuth is going to be removed in 4.2 and should not be used anymore. You can use BasicAuth and set it to respond to a model based on your user table

Generating a key from ancestor path in Google App Engine

I have a model called Request. A request is created with a parent User like so:
request = Request(parentUserKey)
Now, the key_name for a User is that user's email, so when I create a new user, I do:
user = User(key_name = 'abc#gmail.com')
So what I want to do now is to create a key using Key.from_path for a Request, so I try:
requestKey = Key.from_path('User', 'abc#gmail.com', 'Request', 1)
I put 1 because I will use this key to fetch all Requests with ID higher than 1 (or any other arbitrary int) via the following:
requestQuery.filter("__key__ >", requestKey)
Then for testing purposes, I try to convert the key to a string via keyString = str(requestKey), but I get the following error:
Cannot string encode an incomplete key
What am I doing wrong?
To elaborate on what Guido wrote, doing all of this work to manually create a key probably isn't the best approach to solve your problem. Rather, if you store all of User's Request entities in User's entity group, you can simply and straight-forwardly retrieve them with an ancestor query.
First, to make all of the Request entities children of User, we're going to slightly change the way that you instantiate a Request object:
request = Request(parent=parentUser) # Where parentuser is a User already in the datastore
# Do whatever else you need to do to initialize this entity
request.put()
Now, to get all of the Request objects that belong to User, you just:
requests = Request.all().ancestor(parentUser).fetch(1000)
# Obviously, you want to intelligently manage the condition of having
# more that 1000 Requests using cursors if need be.
Having the ability to manually create Keys using all of the path info is great, but it is also often more work than is necessary.
Does this solve your use-case?
A key with a 0 id is not valid. Instead of that filter, use an ancestor query.

Resources