from db.models import UserRole from datetime import datetime AUTH0_DOMAIN = environ['AUTH0_DOMAIN'] AUTH0_CLIENT_ID = environ['AUTH0_CLIENT_ID'] AUTH0_SECRET = environ['AUTH0_SECRET'] AUTH0_AUDIENCE = environ['AUTH0_AUDIENCE'] TOKEN_TMP = "./tmp/token.txt" class CustomAuth0User(Auth0User): email: Optional[str] = Field(None, alias='grand-type') auth = Auth0(domain=AUTH0_DOMAIN, api_audience="ipd-backend", auth0user_model=CustomAuth0User, scopes={'read:email': 'test'}) def get_token(generate=False): if generate: data = { "client_id": AUTH0_CLIENT_ID, "client_secret": AUTH0_SECRET, "audience": AUTH0_AUDIENCE, "grant_type": "client_credentials" } res = r.post(f"https://{AUTH0_DOMAIN}/oauth/token", data=data) res = res.json() with open(TOKEN_TMP, 'w') as access: access.write(res['access_token'])
from starlette.responses import RedirectResponse from uuid import UUID, uuid4 import io import base64 import json import PIL from pydantic import BaseModel, validator, Field from typing import Optional, Any from datetime import datetime from pydantic import BaseModel, create_model from starlette.status import HTTP_401_UNAUTHORIZED from app import mongo auth = Auth0( domain=os.environ["AUTH0_DOMAIN"], api_audience=os.environ["AUTH0_API_AUDIENCE"], ) guest_auth = Auth0( domain=os.environ["AUTH0_DOMAIN"], api_audience=os.environ["AUTH0_API_AUDIENCE"], auto_error=False, ) router = APIRouter(tags=["users"], ) class UserIn(BaseModel): display_name: Optional[str]
from service.util.aws_connector import AWSConnector from service.util.mysql_connector import MySQLConnector from service.company_service import CompanyService, CreateCompanyDto, UpdateCompanyDto, UpdateOrderDto, CreateOrderDto from service.aws_service import AwsService load_dotenv() app = FastAPI() aws_connector = AWSConnector() mysql_connector = MySQLConnector() aws_service = AwsService(aws_connector) company_service = CompanyService(aws_service,mysql_connector) auth = Auth0(domain=os.getenv('AUTH0_DOMAIN'), api_audience=os.getenv('AUTH0_AUDIENCE'), scopes={'read:test':''}) print("Connected to AUTH0") app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/test", status_code=200, dependencies=[Depends(auth.implicit_scheme)]) def test(response: Response, user: Auth0User = Security(auth.get_user)): return user
config = configparser.ConfigParser() config.read('config.ini', encoding='utf-8-sig') con = psycopg2.connect(database=config.get('postgres', 'database'), user=config.get('postgres', 'user'), password=config.get('postgres', 'password'), host=config.get('postgres', 'host'), port=int(config.get('postgres', 'port'))) cur = con.cursor(cursor_factory=RealDictCursor) auth0_domain = os.getenv('AUTH0_DOMAIN', 'suroegin503.eu.auth0.com') auth0_api_audience = os.getenv('AUTH0_API_AUDIENCE', 'https://welcome/') auth = Auth0(domain=auth0_domain, api_audience=auth0_api_audience, scopes={'read:blabla': 'Read BlaBla resource'}) app = FastAPI() def check_prize_place(place: int) -> bool: return True if place > 0 else False '''Получатель награды (приза) в течение 1-ого года, предшествующего назначению повышенной государственной академической стипендии, за результаты проектной деятельности и (или) опытно-конструкторской работы''' @app.get('/api/educ_part/article_writers',
import os from fastapi_auth0 import Auth0 auth = Auth0( domain=os.environ.get("AUTH0_DOMAIN"), api_audience=os.environ.get("AUTH0_API_AUDIENCE"), )