Skip to content
Permalink
Browse files

Changes needed to communicate client<=>crate.

  • Loading branch information...
Vassyli committed Aug 29, 2016
1 parent 90b5232 commit 6e9263376f128fa552fda06c2b05524b9fce4145
@@ -16,6 +16,8 @@
Tools\EntityManagerAwareTrait
};
use Overblog\GraphQLBundle\Definition\Argument;
/**
* Resolver for authentication mutations
*/
@@ -72,9 +74,11 @@ function authWithPassword(string $email = null, string $password = null)
// Save the key and flush.
$key->save($this->getEntityManager());
$argument = new Argument(["apiKey" => $key->getApiKey()]);
$return = $this->container->get("app.graph.resolver.session")->resolve($argument);
return [
"apiKey" => $key->getApiKey(),
"expiresAt" => $key->getExpiresAtAsString(),
"session" => $return,
];
}
@@ -39,7 +39,32 @@ public function resolve(Argument $args = null)
return $return;
}
else {
return null;
if (isset($args["apiKey"])) {
$em = $this->getEntityManager();
$apiKey = $em->getRepository(\LotGD\Crate\GraphQL\Models\ApiKey::class)
->findOneBy(["apiKey" => $args["apiKey"]]);
if ($apiKey !== null) {
$user = $apiKey->getUser();
$userResolver = $this->container->get('app.graph.resolver.user');
$argument = new Argument([
"name" => $user->getName()
]);
return [
"user" => $userResolver->resolve($argument),
"apiKey" => $apiKey->getApiKey(),
"expiresAt" => $apiKey->getExpiresAtAsString()
];
}
}
return [
"user" => null,
"apiKey" => null,
"expiresAt" => null
];
}
}
}
@@ -24,7 +24,7 @@ public function resolve(Argument $args = null)
if ($user instanceof User) {
return [
"id" => $user->getId(),
"id" => (string)$user->getId(),
"name" => $user->getName()
];
}
@@ -15,9 +15,6 @@ AuthWithPasswordPayload:
description: "Authentification answer to fetch apiKey."
config:
fields:
apiKey:
description: "A generated key to use in header to access protected fields."
type: "String!"
expiresAt:
description: "Datetime when the key expires."
type: "String"
session:
description: "The new session."
type: "Session!"
@@ -5,11 +5,11 @@ Query:
fields:
realm:
description: "General information about the server configuration."
type: "Realm"
type: "Realm!"
resolve: "@=resolver('realm_resolver')"
session:
description: "Information about the current session."
type: "Session"
type: "Session!"
resolve: "@=resolver('session_resolver')"
user:
description: "Information about an user account."
@@ -8,11 +8,11 @@ Session:
description: "Information about the current session."
fields:
apiKey:
type: "String!"
type: "String"
description: "ApiKey to this realm."
expiresAt:
type: "String!"
type: "String"
description: "Date this session expires at."
user:
type: "User!"
type: "User"
description: "The user account associated with this session."
@@ -5,7 +5,7 @@ User:
description: "A user account."
fields:
id:
type: "Int!"
type: "String!"
description: "Unique ID of the user."
name:
type: "String!"

0 comments on commit 6e92633

Please sign in to comment.
You can’t perform that action at this time.