Hello everyone I am using the native flow for API ...
# talk-kratos
g
Hello everyone I am using the native flow for API Clients to implement login flow through KRATOS using .NET SDK but I am not able to send the login_challenge in the function call. Can you tell how can i generate the token using ORY hydra after the user is authenticated using kratos?
@bland-eye-99092 @magnificent-energy-493 can you help me out here?
m
Hello @great-crayon-86888 Firstly, for native applications, you must use the API flows which don’t set any cookies. The response contains all data required to render the UI. On successful login, Ory issues a session token that can be used to authenticate subsequent requests to Ory. To generate the token using Ory Hydra after the user is authenticated using Kratos, you need to follow these steps: 1. The login endpoint authenticates the user as usual, for example by username & password, session cookie or other means. Upon successful authentication, the login endpoint redirects the user back to Ory Hydra. 2. Next, Ory Hydra needs the user’s consent. It redirects the user agent to the consent endpoint where the user is asked something like “Do you want to grant MyAnalyticsApp read access to your todo lists? [Yes][no]“. Once the user gives consent by clicking Yes, the consent endpoint redirects back to Ory Hydra. 3. Hydra validates the request and issues the access, refresh, and ID tokens. You can validate the access tokens which are sent to your API directly at Ory Hydra, or use an Identity & Access Proxy like Ory Oathkeeper to do it for you. Regarding the
login_challenge
, it is an optional Hydra login challenge. If present, Kratos will cooperate with Ory Hydra to act as an OAuth2 identity provider. The value for this parameter comes from
login_challenge
URL Query parameter sent to your application (e.g.
/login?login_challenge=abcde
). We dont have specific instructions for the .NET SDK, any contributions there are welcomed!
g
@magnificent-energy-493 I have a few questions over here:- 1. After user authentication in kratos how can we redirect to hydra ? 2. If we are using native api flow once we are successfully logged in using kratos do we need to login again in hydra?
m
1. I havent wired this together myself, but you can check this for reference: https://github.com/ory/examples/tree/master/kratos-hydra 2. No, normally you want the OAuth2 consent session to stay logged in, see also this blogpost: https://www.ory.sh/oauth2-openid-connect-do-you-need-use-cases-examples/ , especially the part about session management I would actually recommend to not use OAuth2 if you can avoid it, because it just adds a lot of complexity, especially around the session management.