0Pricing
OAuth2 & OpenID Connect Deep Dive · レッスン

Identity Providerとの統合

OIDCを使って、Google、Auth0、Oktaなどの一般的なIdentity Provider(IdP)とアプリケーションを統合する方法を学びます。

「Identity Providerとの統合」はCoddyKit上の無料OAuth2 & OpenID Connect Deep Diveレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはOAuth2 & OpenID Connect Deep Dive学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Integrating with Identity Providers

Many apps let you log in with Google, Apple, or social media. These are Identity Providers (IdPs).

Integrating with IdPs simplifies user management for your application. It also offers users a smoother, more secure login experience.

Benefits of Using an IdP

Using an IdP brings several advantages:

  • Single Sign-On (SSO): Users log in once and access multiple services.
  • Reduced Dev Effort: You don't build and maintain your own authentication system.
  • Enhanced Security: IdPs specialize in security, handling passwords and MFA.
  • Better UX: Users prefer familiar login methods.

OIDC: The Identity Bridge

OpenID Connect (OIDC) is the standard protocol for integrating with IdPs.

Built on top of OAuth2, OIDC adds an identity layer. It allows your app to verify the user's identity and get basic profile information.

Registering Your Application

The first step is to register your application with the chosen IdP (e.g., Google, Auth0, Okta).

This process usually involves creating an application entry in their developer console. You'll specify:

  • Application Name
  • Application Type (e.g., Web, Mobile)
  • Redirect URIs: Where the IdP sends the user back after authentication.

Your App's IdP Credentials

Upon registration, the IdP provides your application with specific credentials:

  • Client ID: A public identifier for your application.
  • Client Secret: A confidential key, known only to your app and the IdP (for confidential clients).

These are crucial for your app to communicate securely with the IdP.

Starting User Login

When a user clicks "Login with Google," your application redirects them to the IdP's authorization endpoint.

This redirect URL includes parameters like client_id, redirect_uri, scope (e.g., openid profile email), response_type (code), and state.

Here's a simplified example of how such a URL might be constructed:

public class AuthUrlBuilder {
  public static void main(String[] args) {
    String clientId = "YOUR_CLIENT_ID";
    String redirectUri = "https://your-app.com/callback";
    String scope = "openid profile email";
    String responseType = "code";
    String state = "random_string_for_csrf";

    String authUrl = String.format(
      "https://idp.example.com/oauth2/authorize" +
      "?client_id=%s" +
      "&redirect_uri=%s" +
      "&scope=%s" +
      "&response_type=%s" +
      "&state=%s",
      clientId, redirectUri, scope, responseType, state
    );
    System.out.println("Auth URL starts with: " + authUrl.substring(0, 50) + "...");
  }
}

Receiving the Authorization Code

After the user authenticates successfully at the IdP, the IdP redirects them back to your application's redirect_uri.

This callback URL will contain an authorization code and the state parameter you sent earlier. Your application's callback endpoint must be ready to receive these.

Getting the Identity & Access Tokens

Your application then makes a secure, back-channel (server-to-server) request to the IdP's token endpoint.

It exchanges the authorization code (along with client_id and client_secret) for:

  • ID Token: A JWT containing user identity information.
  • Access Token: Used to access protected resources (APIs).
  • Refresh Token: For obtaining new access tokens without re-authentication.

Decoding the ID Token

The ID Token is a JSON Web Token (JWT). It contains claims about the authenticated user, such as their unique ID (sub), name (name), and email (email).

Your application decodes this token to retrieve these claims, which identify the user within your system.

Try running this simplified example to see how claims are extracted from a mock ID token:

import java.util.Base64;
import org.json.JSONObject;

public class IdTokenDecoder {
  public static void main(String[] args) {
    // This is a mock ID token (header.payload.signature)
    String mockIdToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
                         "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkphbmUgRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." +
                         "signature_part_is_ignored_for_parsing";

    String[] parts = mockIdToken.split("\\.");
    if (parts.length < 2) {
        System.out.println("Invalid token format.");
        return;
    }
    
    String payloadBase64 = parts[1];
    String decodedPayload = new String(Base64.getUrlDecoder().decode(payloadBase64));
    
    JSONObject jsonPayload = new JSONObject(decodedPayload);
    
    System.out.println("User ID (sub): " + jsonPayload.getString("sub"));
    System.out.println("Name: " + jsonPayload.getString("name"));
  }
}

Quick Check: IdP Benefits

Which of the following are primary benefits of integrating your application with a third-party Identity Provider (IdP) using OpenID Connect (OIDC)?

IdP Integration: Key Takeaways

In this lesson, we explored how to integrate your applications with Identity Providers using OpenID Connect.

You learned about the benefits of IdPs, the client registration process, initiating the OIDC authentication flow, handling callbacks, and extracting user claims from the ID Token.

This integration streamlines user management and enhances security for your applications.

よくある質問

「Identity Providerとの統合」レッスンは無料ですか?

はい。「Identity Providerとの統合」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、OAuth2 & OpenID Connect Deep Diveコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。

「Identity Providerとの統合」で何を学びますか?

OIDCを使って、Google、Auth0、Oktaなどの一般的なIdentity Provider(IdP)とアプリケーションを統合する方法を学びます。 ブラウザで直接実行するハンズオンコードでOAuth2 & OpenID Connect Deep Diveを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

OAuth2 & OpenID Connect Deep Diveを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのOAuth2 & OpenID Connect Deep Diveは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「Identity Providerとの統合」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このOAuth2 & OpenID Connect Deep Diveレッスンでコードを書いて実行できますか?

はい。すべてのOAuth2 & OpenID Connect Deep Diveレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Identity Providerとの統合
  2. マイクロサービスとAPI Gatewayのセキュリティ
  3. 多要素認証(MFA)
  4. アプリケーション間のシングルサインオン
← OAuth2 & OpenID Connect Deep Diveに戻る