Обзор основных типов предоставления
Получите начальное представление о различных типах предоставления авторизации и о том, когда обычно используется каждый из них в разных сценариях приложений.
«Обзор основных типов предоставления» — бесплатный урок OAuth2 & OpenID Connect Deep Dive на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения OAuth2 & OpenID Connect Deep Dive, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
What Are Grant Types?
In OAuth2, Authorization Grant Types are the different methods a client application uses to obtain an access token from the authorization server.
Think of them as various "workflows" or "strategies" tailored for different client types and security needs.
Each type dictates how the client proves its identity and gets permission to access a user's (or its own) resources.
Authorization Code Flow (Web Apps)
This is the most widely recommended and secure grant type, especially for confidential clients like traditional web applications running on a server.
The client exchanges an authorization code (received from the user's browser) for an access token directly with the authorization server. This keeps the access token out of the browser's URL.
Client Credentials Flow (Machine-to-Machine)
The Client Credentials flow is used when a client application needs to access protected resources on its own behalf, rather than on behalf of a user.
There's no user involvement. It's ideal for machine-to-machine communication, like a backend service calling an API, where the client itself is the "resource owner."
Implicit Flow (Client-Side, Deprecated)
Historically, the Implicit flow was used by public clients (like single-page applications or mobile apps) that couldn't securely store a client secret.
It returns the access token directly to the browser via the URL fragment. Due to security concerns (token leakage, no refresh tokens), it is now largely deprecated in favor of the Authorization Code Flow with PKCE.
Resource Owner Password Credentials (Avoid!)
This flow involves the client directly collecting the user's username and password and sending them to the authorization server to obtain an access token.
It's generally highly discouraged because it requires the client to handle sensitive user credentials, which is a major security risk. Only use in highly trusted, first-party legacy applications where no other option exists.
PKCE: Securing Public Clients
With the deprecation of the Implicit Flow, how do public clients (like mobile apps or SPAs) get tokens securely?
The Authorization Code Flow with PKCE (Proof Key for Code Exchange) is the modern answer. PKCE adds a cryptographic protection layer, making the Authorization Code flow safe for clients that cannot hold a secret.
It's now the recommended approach for these client types.
Grant Types at a Glance
Choosing the right grant type depends on your application's nature:
- Authorization Code: Secure for web server apps. With PKCE, also for mobile/SPAs.
- Client Credentials: For machine-to-machine API access.
- Implicit: Largely deprecated, avoid for new development.
- Resource Owner Password Credentials: Avoid, high security risk.
Access Tokens: The Goal
No matter which grant type you use, the ultimate goal is to obtain an Access Token.
An Access Token is a credential that allows the client to access protected resources on behalf of the user (or itself) from the Resource Server. It's typically a short-lived, opaque string or a JWT.
Why Multiple Workflows?
Different application architectures have varying capabilities to protect sensitive information.
OAuth2 provides these distinct grant types to offer secure options for diverse clients, from backend services to browser-based apps, ensuring appropriate security measures for each context.
Choose the Best Grant Type
A new e-commerce platform wants to allow users to log in using their social media accounts (e.g., Google, Facebook) and grant the platform access to their public profile information. The platform is built as a traditional web application with a backend server.
Recap: Core Grant Types Overview
We've explored the core OAuth2 grant types: Authorization Code (most secure, for web apps and public clients with PKCE), Client Credentials (for machine-to-machine), Implicit (deprecated), and Resource Owner Password Credentials (highly discouraged).
Understanding these different workflows helps you choose the most secure and suitable method for your specific application's authorization needs.
Часто задаваемые вопросы
Урок «Обзор основных типов предоставления» бесплатный?
Да — полный текст урока «Обзор основных типов предоставления» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс OAuth2 & OpenID Connect Deep Dive, подпишись на CoddyKit PRO. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.
Чему я научусь в уроке «Обзор основных типов предоставления»?
Получите начальное представление о различных типах предоставления авторизации и о том, когда обычно используется каждый из них в разных сценариях приложений. Ты практикуешь OAuth2 & OpenID Connect Deep Dive с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать OAuth2 & OpenID Connect Deep Dive?
Предыдущий опыт не требуется. OAuth2 & OpenID Connect Deep Dive на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.
Сколько времени занимает урок «Обзор основных типов предоставления»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке OAuth2 & OpenID Connect Deep Dive?
Да. Каждый урок OAuth2 & OpenID Connect Deep Dive включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- OAuth2: протокол делегирования
- Роли и терминология OAuth2
- Обзор основных типов предоставления
- Токены доступа, токены обновления и области действия