Package Data | |
---|---|
Maintainer Username: | joselfonseca |
Maintainer Contact: | jose@ditecnologia.com (Jose Luis Fonseca) |
Package Create Date: | 2019-01-21 |
Package Last Update: | 2024-08-06 |
Home Page: | https://lighthouse-php-auth.com/ |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:19:45 |
Package Statistics | |
---|---|
Total Downloads: | 630,028 |
Monthly Downloads: | 8,970 |
Daily Downloads: | 297 |
Total Stars: | 232 |
Total Watchers: | 10 |
Total Forks: | 55 |
Total Open Issues: | 3 |
GraphQL mutations for Laravel Passport using Lighthouse PHP ^3.2.
You can see this tutorial for installation and usage.
Make sure you have Laravel Passport installed.
To install run composer require joselfonseca/lighthouse-graphql-passport-auth
.
ServiceProvider will be attached automatically
Add the following env vars to your .env
PASSPORT_CLIENT_ID=
PASSPORT_CLIENT_SECRET=
You are done with the installation!
By default the schema is defined internally in the package, if you want to override the schema or resolvers, you can publish the package configuration and default schema by running:
php artisan vendor:publish --provider="Joselfonseca\LighthouseGraphQLPassport\Providers\LighthouseGraphQLPassportServiceProvider"
This command will publish a configuration file lighthouse-graphql-passport.php
and a schema file in /graphql/auth.graphgl
that looks like this:
input LoginInput {
username: String!
password: String!
}
input RefreshTokenInput {
refresh_token: String
}
type User {
id: ID!
name: String!
email: String!
}
type AuthPayload {
access_token: String!
refresh_token: String!
expires_in: Int!
token_type: String!
user: User!
}
type RefreshTokenPayload {
access_token: String!
refresh_token: String!
expires_in: Int!
token_type: String!
}
type LogoutResponse {
status: String!
message: String
}
type ForgotPasswordResponse {
status: String!
message: String
}
input ForgotPasswordInput {
email: String! @rules(apply: ["required", "email"])
}
input NewPasswordWithCodeInput {
email: String! @rules(apply: ["required", "email"])
token: String! @rules(apply: ["required", "string"])
password: String! @rules(apply: ["required", "confirmed", "min:8"])
password_confirmation: String!
}
input RegisterInput {
name: String! @rules(apply: ["required", "string"])
email: String! @rules(apply: ["required", "email"])
password: String! @rules(apply: ["required", "confirmed", "min:8"])
password_confirmation: String!
}
extend type Mutation {
login(input: LoginInput @spread): AuthPayload! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\Login@resolve")
refreshToken(input: RefreshTokenInput @spread): RefreshTokenPayload! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\RefreshToken@resolve")
logout: LogoutResponse! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\Logout@resolve")
forgotPassword(input: ForgotPasswordInput! @spread): ForgotPasswordResponse! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\ForgotPassword@resolve")
updateForgottenPassword(input: NewPasswordWithCodeInput @spread): ForgotPasswordResponse! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\ResetPassword@resolve")
register(input: RegisterInput @spread): AuthPayload! @field(resolver: "Joselfonseca\\LighthouseGraphQLPassport\\GraphQL\\Mutations\\Register@resolve")
}
In the configuration file you can now set the schema file to be used for the exported one like this:
/*
|--------------------------------------------------------------------------
| GraphQL schema
|--------------------------------------------------------------------------
|
| File path of the GraphQL schema to be used, defaults to null so it uses
| the default location
|
*/
'schema' => base_path('graphql/auth.graphql')
This will allow you to change the schema and resolvers if needed.
This will add 6 mutations to your GraphQL API
extend type Mutation {
login(input: LoginInput): AuthPayload!
refreshToken(input: RefreshTokenInput): RefreshTokenPayload!
logout: LogoutResponse!
forgotPassword(input: ForgotPasswordInput!): ForgotPasswordResponse!
updateForgottenPassword(input: NewPasswordWithCodeInput): ForgotPasswordResponse!
register(input: RegisterInput @spread): AuthPayload!
}
When an application that needs to be re compiled and re deploy to stores like an iOS app needs to change the client for whatever reason, it becomes a blocker for QA or even brakes the production app if the client is removed. The app will not work until the new version with the updated keys is deployed. There are alternatives to store this configuration in the client but for this use case we are relying on the backend to be the OAuth client
Please see the releases page https://github.com/joselfonseca/lighthouse-graphql-passport-auth/releases
To run the test in this package, navigate to the root folder of the project and run
composer install
Then
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email jose at ditecnologia dot com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.