Neoteroi / BlackSheep

Fast ASGI web framework for Python
https://www.neoteroi.dev/blacksheep/
MIT License
1.8k stars 75 forks source link

Google oidc #357

Closed Nicialy closed 1 year ago

Nicialy commented 1 year ago

Describe the bug I try insert redirect in openidc

google_oidc = use_openid_connect(
    app,
    OpenIDSettings(
        authority="https://accounts.google.com/o/oauth2/v2/auth",
        client_id=settings.GOOGLE_CLIENT_ID,
        client_secret=settings.GOOGLE_CLIENT_SECRET,
        redirect_uri="http://localhost:5000/api/google",
        callback_path="/api/google-callback",
        entry_path="/api/sign-in-google",
        logout_path="/api/sign-out-google",
        discovery_endpoint="https://accounts.google.com/.well-known/openid-configuration",
    ),
    tokens_store=CookiesTokensStore(),
)

And My events.on_id_token_validated dont work

@google_oidc.events.on_id_token_validated
async def id_token_callback(context, response):
    # somithing doing with response

And redirect dont save myinfo about user

@app.router.post("/api/google")
async def home(user: Identity):
    if user.is_authenticated():
        response = pretty_json(user.claims)

        return response

    return html("<a href='/api/sign-in-google'>Sign in</a><br/>")

user.is_auth every time false How i can correct my code?

RobertoPrevato commented 1 year ago

Hi @Nicialy Thank you for reporting this issue, and sorry for taking so much time to write a reply. I did not have time to look into this, but I should have time this weekend.

RobertoPrevato commented 1 year ago

I just made a test and I successfully made an example where I obtain an id_token from Google.

I published working examples here:

For some additional information, please see a message here: https://github.com/Neoteroi/BlackSheep/issues/358#issuecomment-1595657372