Commit 2aa7c79c by Евгений

Улучшение #19447

Добавление токенов
1 parent f8ae3ce4
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Validation\Rule;
use Inertia\Inertia;
class TokensController extends Controller
{
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tokens extends Model
{
use HasFactory;
}
<?php
namespace App\Service;
interface API{
function getAuthLink();
function getToken($code);
}
<?php
namespace App\Service;
class ApiCommon implements API {
function getAuthLink()
{
return 'https://oauth.yandex.ru/authorize?response_type=code&client_id=' . config('api.yandex.id');
}
function getToken($code)
{
// TODO: Implement getToken() method.
}
}
<?php
namespace App\Service;
class YandexDirect extends ApiCommon{
function getAuthLink()
{
return 'https://oauth.yandex.ru/authorize?response_type=code&client_id=' . config('api.yandex.id');
}
function getToken($code)
{
// TODO: Implement getToken() method.
}
}
<?php
//https://oauth.yandex.ru/client/41fef5d911a54f63b685c8155d189b61
return [
'yandex' => [
'id' => '41fef5d911a54f63b685c8155d189b61',
'password' => '6877d3260db04475adb9eae3518584f5'
]
];
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tokens', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tokens');
}
}
# ----------------------------
# Host config
# ----------------------------
server {
listen %ip%:%httpport%;
listen %ip%:%httpsport% ssl http2;
server_name %host% %aliases%;
root '%hostdir%';
limit_conn addr 64;
autoindex off;
index index.php index.html index.htm;
ssl_certificate '%sprogdir%/userdata/config/cert_files/server.crt';
ssl_certificate_key '%sprogdir%/userdata/config/cert_files/server.key';
client_max_body_size 150m;
# ssl_trusted_certificate '';
# Force HTTPS
# add_header Strict-Transport-Security 'max-age=2592000' always;
# if ($scheme ~* ^(?!https).*$) {
# return 301 https://$host$request_uri;
# }
# Force www.site.com => site.com
# if ($host ~* ^www\.(.+)$) {
# return 301 $scheme://$1$request_uri;
# }
# Disable access to backup/config/command/log files
# if ($uri ~* ^.+\.(?:bak|co?nf|in[ci]|log|orig|sh|sql|tar|sql|t?gz|cmd|bat)$) {
# return 404;
# }
# Disable access to hidden files/folders
if ($uri ~* /\.(?!well-known)) {
return 404;
}
# Disable MIME sniffing
add_header X-Content-Type-Options 'nosniff' always;
location ~* ^.+\.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 1d;
access_log off;
}
location / {
# Force index.php routing (if not found)
try_files $uri $uri/ /index.php?$query_string;
if ($request_method = OPTIONS) {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000 always;
add_header 'Content-Type' 'text/plain; charset=utf-8' always;
add_header 'Content-Length' 0 always;
return 204;
}
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,Authorization' always;
# Force index.php routing (all requests)
# rewrite ^/(.*)$ /index.php?/$1 last;
location ~ \.php$ {
try_files $fastcgi_script_name =404;
# limit_conn addr 16;
# limit_req zone=flood burst=32 nodelay;
# add_header X-Frame-Options 'SAMEORIGIN' always;
# add_header Referrer-Policy 'no-referrer-when-downgrade' always;
# CSP syntax: <host-source> <scheme-source>(http: https: data: mediastream: blob: filesystem:) 'self' 'unsafe-inline' 'unsafe-eval' 'none'
# Content-Security-Policy-Report-Only (report-uri https://site.com/csp/)
# add_header Content-Security-Policy "default-src 'self'; connect-src 'self'; font-src 'self'; frame-src 'self'; img-src 'self'; manifest-src 'self'; media-src 'self'; object-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests" always;
fastcgi_pass backend;
include '%sprogdir%/userdata/config/nginx_fastcgi_params.txt';
}
}
# Service configuration (do not edit!)
# ----------------------------
location /openserver/ {
root '%sprogdir%/modules/system/html';
autoindex off;
index index.php index.html index.htm;
%allow%allow all;
allow 127.0.0.0/8;
allow ::1/128;
allow %ips%;
deny all;
location ~* ^/openserver/.+\.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 1d;
access_log off;
}
location /openserver/server-status {
stub_status on;
}
location ~ ^/openserver/.*\.php$ {
try_files $fastcgi_script_name =404;
fastcgi_index index.php;
fastcgi_pass backend;
include '%sprogdir%/userdata/config/nginx_fastcgi_params.txt';
}
}
# End service configuration
# ----------------------------
}
# ----------------------------
# End host config
# ----------------------------
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
<div class="mb-8 flex"> <div class="mb-8 flex">
<inertia-link class="btn-indigo" href="/500">500 error</inertia-link> <inertia-link class="btn-indigo" href="/500">500 error</inertia-link>
<inertia-link class="btn-indigo ml-1" href="/404">404 error</inertia-link> <inertia-link class="btn-indigo ml-1" href="/404">404 error</inertia-link>
<a class="btn-indigo ml-1" href="https://oauth.yandex.ru/authorize?response_type=code&client_id=41fef5d911a54f63b685c8155d189b61">
Add Token
</a>
</div> </div>
<p class="leading-normal">👆 These links are intended to be broken to illustrate how error handling works with Inertia.js.</p> <p class="leading-normal">👆 These links are intended to be broken to illustrate how error handling works with Inertia.js.</p>
</div> </div>
......
...@@ -7,6 +7,7 @@ use App\Http\Controllers\ImagesController; ...@@ -7,6 +7,7 @@ use App\Http\Controllers\ImagesController;
use App\Http\Controllers\OrganizationsController; use App\Http\Controllers\OrganizationsController;
use App\Http\Controllers\ReportsController; use App\Http\Controllers\ReportsController;
use App\Http\Controllers\UsersController; use App\Http\Controllers\UsersController;
use App\Http\Controllers\TokensController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
/* /*
...@@ -149,3 +150,7 @@ Route::get('500', function () { ...@@ -149,3 +150,7 @@ Route::get('500', function () {
echo $fail; echo $fail;
}); });
Route::get('/token/{type}', [TokensController::class, 'token'])
->name('token')
->middleware('auth');
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!