In the Ory ecosystem, the service responsible for generating authentication tokens or authorization codes depends on the type of authentication flow you are implementing: -
For OAuth2 and OpenID Connect flows (including authorization code and client credentials grants): The service that generates authorization codes and tokens is
Ory Hydra (or Ory OAuth2 & OpenID Connect in Ory Network). When a client application initiates an OAuth2 flow, Ory Hydra issues the authorization code and, upon exchange, the access and ID tokens. The actual code/token generation is handled by the OAuth2 server, not by the client or a separate service. The client (your app or service) requests these from Ory Hydra by following the appropriate OAuth2 flow (e.g., authorization code flow, client credentials flow) [Run your own OAuth2 Server](
https://www.ory.sh/blog/run-oauth2-server-open-source-api-security/) [Try common OAuth2 Grants](
https://www.ory.sh/docs/getting-started/ory-network-oauth2/). -
For user authentication (login, registration, etc.): Ory Kratos handles user authentication and issues session cookies or tokens after successful login. However, Kratos does not generate OAuth2 authorization codes or access tokens; it is focused on user identity and session management [Ory Ecosystem Introduction](
https://www.ory.sh/docs/ecosystem/projects/).
Summary: - The
OAuth2 server (Ory Hydra) is responsible for generating authorization codes and tokens in OAuth2 flows. - The
identity server (Ory Kratos) is responsible for user authentication and session management, not for issuing OAuth2 tokens. If you need to implement machine-to-machine authentication or OAuth2 flows, the service (Ory Hydra) should generate the tokens or codes—not your application or a separate service. Your application should request them from Ory Hydra using the appropriate protocol.