XF 2.2 User API Keys

Tapple

Member
I have done a lot of digging around the API endpoints, and I don't see a way to programmatically generate API keys. I want to create a mobile app for my forum, but from what I have seen so far, you cannot create a forum post or thread as another user, unless you are using an API key with that user associated with it. Is there anyway to create an API key for the user if they dont already have on upon login for instance? If not, has anyone found out a way in which I can make this app happen without manually creating an API key for each user? Any addons or custom scripts? Need about 3.5k keys for my users.
 
PHP:
$apiKey = $this->em()->create('XF:ApiKey');

$keyScopes = [
    // SET YOUR API SCOPES HERE.
];

$keyManager = $this->service('XF:ApiKey\Manager', $apiKey);
$keyManager->setTitle('Auto Key: ' . \XF::visitor()->username);
$keyManager->setActive(true);
$keyManager->setScopes(false, $keyScopes);
$keyManager->setKeyType('user', \XF::visitor()->username);
$keyManager->save();
 
Back
Top Bottom