Skip to content

Commit 09ffeff

Browse files
author
Steve Porter
committed
feat: initial commit
1 parent adb42d4 commit 09ffeff

10 files changed

+407
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.project
2+
*.sublime-project
3+
*.sublime-workspace
4+
.DS_Store
5+
.idea/
6+
composer.lock
7+
composer.phar
8+
phpunit.phar
9+
vendor

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-mongodb-passport` will be documented in this file
4+
5+
## 1.0.0 - 2018-01-10
6+
- initial release

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Laravel MongoDB Passport
2+
===============
3+
4+
[![Latest Stable Version](http://img.shields.io/github/release/steveporter92/laravel-mongodb-passport.svg)](https://packagist.org/packages/steveporter92/laravel-mongodb-passport) [![Total Downloads](http://img.shields.io/packagist/dm/steveporter92/laravel-mongodb-passport.svg)](https://packagist.org/packages/steveporter92/laravel-mongodb-passport)
5+
6+
A service provider to add support for [Laravel Passport](https://github.com/laravel/passport) and [MongoDB](https://github.com/jenssegers/laravel-mongodb).
7+
8+
Table of contents
9+
-----------------
10+
* [Installation](#installation)
11+
12+
Installation
13+
------------
14+
15+
Installation using composer:
16+
17+
```
18+
composer require steveporter92/laravel-mongodb-passport
19+
```
20+
21+
### Laravel version Compatibility
22+
23+
Laravel | Package
24+
:---------|:----------
25+
5.5.x | 1.0.x
26+
27+
And add the service provider in `config/app.php`:
28+
29+
```php
30+
StevePorter92\Mongodb\MongodbPassportServiceProvider::class,
31+
```
32+
33+
For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`.
34+
35+
```php
36+
$app->register(StevePorter92\Mongodb\MongodbPassportServiceProvider::class);
37+
```
38+
39+
The service provider will overide the default laravel passport models in order to use mongodb's implementation of eloquent. There is no need to register any additional classes or add any additional configuration other than those outlined in [Laravel Passport](https://github.com/laravel/passport) and [MongoDB](https://github.com/jenssegers/laravel-mongodb).

composer.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "steveporter92/laravel-mongodb-passport",
3+
"description": "A package to allow laravel/passport use with jenssegers/laravel-mongodb",
4+
"homepage": "https://github.com/steveporter92/laravel-mongodb-passport",
5+
"license": "MIT",
6+
"keywords": [
7+
"laravel",
8+
"laravel-mongodb",
9+
"laravel-mongodb-passport",
10+
"laravel-passport",
11+
"mongodb",
12+
"passport",
13+
"steveporter92"
14+
],
15+
"require": {
16+
"illuminate/support": "^5.5",
17+
"jenssegers/mongodb": "3.3.*",
18+
"laravel/passport": "4.0.*"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"StevePorter92\\Mongodb\\": "src"
23+
}
24+
},
25+
"authors": [
26+
{
27+
"name": "Steve Porter",
28+
"email": "[email protected]",
29+
"role": "Developer"
30+
}
31+
],
32+
"extra": {
33+
"laravel": {
34+
"providers": [
35+
"StevePorter92\\Mongodb\\MongodbPassportServiceProvider"
36+
]
37+
}
38+
}
39+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace StevePorter92\Mongodb;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use StevePorter92\Mongodb\Passport\AuthCode;
7+
use StevePorter92\Mongodb\Passport\Client;
8+
use StevePorter92\Mongodb\Passport\PersonalAccessClient;
9+
use StevePorter92\Mongodb\Passport\Token;
10+
11+
class MongodbPassportServiceProvider extends ServiceProvider
12+
{
13+
public function register()
14+
{
15+
/*
16+
* Passport client extends Eloquent model by default, so we alias them.
17+
*/
18+
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
19+
$loader->alias('Laravel\Passport\AuthCode', AuthCode::class);
20+
$loader->alias('Laravel\Passport\Client', Client::class);
21+
$loader->alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class);
22+
$loader->alias('Laravel\Passport\Token', Token::class);
23+
}
24+
}

src/Passport/AuthCode.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace StevePorter92\Mongodb\Passport;
4+
5+
use Jenssegers\Mongodb\Eloquent\Model;
6+
7+
class AuthCode extends Model
8+
{
9+
/**
10+
* The database table used by the model.
11+
*
12+
* @var string
13+
*/
14+
protected $table = 'oauth_auth_codes';
15+
16+
/**
17+
* The guarded attributes on the model.
18+
*
19+
* @var array
20+
*/
21+
protected $guarded = [];
22+
23+
/**
24+
* The attributes that should be cast to native types.
25+
*
26+
* @var array
27+
*/
28+
protected $casts = [
29+
'revoked' => 'bool',
30+
];
31+
32+
/**
33+
* The attributes that should be mutated to dates.
34+
*
35+
* @var array
36+
*/
37+
protected $dates = [
38+
'expires_at',
39+
];
40+
41+
/**
42+
* Get the client that owns the authentication code.
43+
*
44+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
45+
*/
46+
public function client()
47+
{
48+
return $this->hasMany(Client::class);
49+
}
50+
}

src/Passport/Client.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace StevePorter92\Mongodb\Passport;
4+
5+
use Jenssegers\Mongodb\Eloquent\Model;
6+
7+
class Client extends Model
8+
{
9+
/**
10+
* The database table used by the model.
11+
*
12+
* @var string
13+
*/
14+
protected $table = 'oauth_clients';
15+
16+
/**
17+
* The guarded attributes on the model.
18+
*
19+
* @var array
20+
*/
21+
protected $guarded = [];
22+
23+
/**
24+
* The attributes excluded from the model's JSON form.
25+
*
26+
* @var array
27+
*/
28+
protected $hidden = [
29+
'secret',
30+
];
31+
32+
/**
33+
* The attributes that should be cast to native types.
34+
*
35+
* @var array
36+
*/
37+
protected $casts = [
38+
'personal_access_client' => 'bool',
39+
'password_client' => 'bool',
40+
'revoked' => 'bool',
41+
];
42+
43+
/**
44+
* Get all of the authentication codes for the client.
45+
*
46+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
47+
*/
48+
public function authCodes()
49+
{
50+
return $this->hasMany(AuthCode::class);
51+
}
52+
53+
/**
54+
* Get all of the tokens that belong to the client.
55+
*
56+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
57+
*/
58+
public function tokens()
59+
{
60+
return $this->hasMany(Token::class);
61+
}
62+
63+
/**
64+
* Determine if the client is a "first party" client.
65+
*
66+
* @return bool
67+
*/
68+
public function firstParty()
69+
{
70+
return $this->personal_access_client || $this->password_client;
71+
}
72+
}

src/Passport/PersonalAccessClient.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace StevePorter92\Mongodb\Passport;
4+
5+
use Jenssegers\Mongodb\Eloquent\Model;
6+
7+
class PersonalAccessClient extends Model
8+
{
9+
/**
10+
* The database table used by the model.
11+
*
12+
* @var string
13+
*/
14+
protected $table = 'oauth_personal_access_clients';
15+
16+
/**
17+
* The guarded attributes on the model.
18+
*
19+
* @var array
20+
*/
21+
protected $guarded = [];
22+
23+
/**
24+
* Get all of the authentication codes for the client.
25+
*
26+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
27+
*/
28+
public function client()
29+
{
30+
return $this->belongsTo(Client::class);
31+
}
32+
}

0 commit comments

Comments
 (0)