Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement fastapi-oidc in my app? #34

Open
stribizhev opened this issue Jul 28, 2022 · 0 comments
Open

How to implement fastapi-oidc in my app? #34

stribizhev opened this issue Jul 28, 2022 · 0 comments

Comments

@stribizhev
Copy link

Can you please provide a complete walk-through how to implement the example in an existing code?

I received the client_id, base_authorization_server_uri, issuer (must be the same as base_authorization_server_uri in my case, this is what I was told ), and I have tried using the code as shown in the readme with these values, but all I get is an empty "Available authorizations" dialog and "Not authenticated" error message in the Swagger UI.

So, what else should be added to a code in main.py like

import datetime, os, random, time
from pathlib import Path
from typing import Union, Optional
from fastapi import FastAPI, Depends, File, UploadFile, status
from fastapi.responses import FileResponse

from collections.abc import Callable
from fastapi_oidc import IDToken, get_auth

OIDC_config = {
    "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "base_authorization_server_uri": "https://url",
    "issuer": "https://url",
    "signature_cache_ttl": 3600,
}
swagger_ui_init_oauth = {
    "clientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "appName": "name",
    "usePkceWithAuthorizationCodeGrant": "true",
    ###"clientSecret": "secret",   ### Told not to use it if I use PKCE
    "oauth2RedirectUrl": "https://redirURL",
    "scopeSeparator": " ",
    "scopes": "scopes...",
}

authenticate_user: Callable = get_auth(**OIDC_config)

app = FastAPI(swagger_ui_init_oauth=swagger_ui_init_oauth)

@app.post("/highlight_file/", tags=['highlight_file'])
async def highlight_file(file: UploadFile = File(...), id_token: IDToken = Depends(authenticate_user)):
    print(f'ID Token: {id_token}')
    return await highlight_file_function(file)

async def highlight_file_function(file):
    # process file code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant