The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

よく知られたOpenID Connect プロバイダーの設定

This document explains how to configure well-known social OIDC and OAuth2 providers.

はじめに

If you use OpenID Connect Authorization Code Flow to protect Quarkus endpoints, then you need to configure Quarkus to tell it how to connect to OpenID Connect providers, how to authenticate to such providers, which scopes to use, and so on.

Sometimes you need to use the configuration to work around the fact that some providers do not implement OpenID Connect completely or when they are in fact OAuth2 providers only.

このようなプロバイダーの設定は、複雑で非常に技術的になり、理解が困難になる可能性があります。

よく知られた OpenID Connect および OAuth2 プロバイダーを参照するために、quarkus.oidc.provider 設定プロパティーが導入されました。このプロパティーを使用して、最小限のカスタマイズのみが必要な github などのプロバイダーを参照することができます。通常、アカウント固有の client idclient secret およびいくつかのプロパティーを設定して設定を完了する必要があります。

このプロパティーは、application.properties、複数のプロバイダーを設定する必要がある場合は マルチテナント セットアップ (たとえば、 Quarkus Renarde security documentation ) を参照)、テナント設定が動的に作成される場合はカスタムの TenantConfigResolvers で使用することができます。

よく知られたプロバイダー

GitHub

GitHub の OIDC を設定するには、 GitHub developer settings で新しい OAuth アプリケーションを作成する必要があります。

oidc github 1

詳細を適切に入力する必要がありますが、さらに重要なのは、Authorization Callback URL を http://localhost:8080/_renarde/security/github-success に設定することです (Quarkus DEV モードを使用してテストする場合)。

次に、Register application をクリックすると、アプリケーションページが表示されます。

oidc github 2

Generate a new client secret をクリックし、クレデンシャルを確認して、Client ID と Client Secret を書き留める必要があります (特に Client Secret は、後でこのページで再度見ることができないため、書き留めてください。ただし、いつでも再作成できますので、心配しすぎる必要はありません)。

oidc github 3

次に、以下の設定を application.properties に追加します。

quarkus.oidc.provider=github
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Secret>

quarkus.oidc.provider=github will request GitHub to add a user:email scope to issued access tokens. For information about overriding this scope or requesting more scopes, see the Provider scopes section.

You can also send access tokens issued by GitHub to quarkus.oidc.application-type=service or quarkus.oidc.application-type=hybrid Quarkus applications.

Google

OIDC for Google を設定するには、 Google Cloud Platform console で新しいプロジェクトを作成する必要があります。

プロジェクト名を選択し、CREATE をクリックします。

oidc google 1

次に、トップセレクターでプロジェクトを選択し、左側のメニューバーから APIs and Services > OAuth consent screen をクリックします。

oidc google 2

External を選択して、Google ユーザーがアプリケーションにログインすることを許可し、CREATE を押します。

oidc google 3

これで、アプリケーション名、サポートメール、開発者の連絡先情報を入力して、SAVE AND CONTINUE を押すことができます。

oidc google 4

次のページにスコープを追加せずに、SAVE AND CONTINUE を押します。

oidc google 5

次のページにテストユーザーを追加せずに、SAVE AND CONTINUE を押します。

oidc google 6

トップメニューの CREATE CREDENTIALS > OAuth client ID をクリックします。

oidc google 7

Application type として Web application を選択し、Authorised redirect URIs リストに http://localhost:8080/_renarde/security/oidc-success を追加して、CREATE を押します。

oidc google 8

Client ID と Client Secret をコピーします。

oidc google 9

これで、application.properties を設定できます。

quarkus.oidc.provider=google
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Secret>

quarkus.oidc.provider=google will request Google to add openid, email and profile scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

You can also send access tokens issued by Google to quarkus.oidc.application-type=service or quarkus.oidc.application-type=hybrid Quarkus applications.

Microsoft

Microsoft 用の OIDC をセットアップするには、 Microsoft Azure Portal にアクセスし、Azure Active Directory を検索してクリックする必要があります。

oidc microsoft 1

そこで、左側の Manage の下にある App registrations をクリックしてから、New registration をクリックします。

oidc microsoft 2

アプリケーション名を入力し、Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox) を選択して誰でもログインできるようにし、 Web Redirect URI を http://localhost:8080/_renarde/security/oidc-success として追加してから Register をクリックします。

oidc microsoft 3

その結果のページで、Client Id (Application (client) ID の下) をコピーしてから、Add a certificate or secret をクリックします。

oidc microsoft 4

次に、Client secrets (0) の下にある New client secret をクリックします。

oidc microsoft 5

何も変更せずに、そのダイアログで Add をクリックします。

oidc microsoft 6

結果のページで、Secret ID をコピーします。

oidc microsoft 7

これで、application.properties を設定できます。

quarkus.oidc.provider=microsoft
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Secret>

quarkus.oidc.provider=microsoft will request Microsoft to add openid, email and profile scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

You can also send access tokens issued by Microsoft to quarkus.oidc.application-type=service or quarkus.oidc.application-type=hybrid Quarkus applications but you may need to set quarkus.oidc.verify-access-token-with-user-info configuration property to true if access tokens issued by Microsoft are not in JWT format.

Some Microsoft services may issue tokens whose signatures can only be verified if the current token’s nonce header is reset with its SHA-256 digest value. If your application has to deal with such tokens then please enable an Azure token customizer:

quarkus.oidc.provider=microsoft
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Secret>
quarkus.oidc.token.customizer-name=azure-access-token-customizer

Apple

Apple 用の OIDC を設定するには、開発者アカウントを作成し、99 ユーロ/年のプログラムにサインアップする必要がありますが、他のほとんどの OIDC プロバイダーのように localhost でアプリケーションをテストすることはできません。https で実行して公開する必要があるため、開発目的では https://ngrok.com などのサービスを使用することをお勧めします。

Create a new identifier にアクセスして + を押します

oidc apple 1

何も触れないで、App IDs を選択したまま Continue を押します。

oidc apple 2

何も触れないで、App を選択したまま Continue を押します。

oidc apple 3

説明とバンドル ID を入力します (アプリケーションパッケージ名を使用します)。

oidc apple 4

次に、下にスクロールして Sign in with Apple 機能を見つけ、それを選択して、Continue を押します。

oidc apple 5

アプリ ID 接頭辞を書き留めてから、Register を押します。

oidc apple 6

Identifiers ページに戻り、 + を押します。

oidc apple 7

Service IDs を選択し、Continue を押します。

oidc apple 8

説明とバンドル ID を入力 (アプリケーションパッケージ名を使用) し、Continue を押します。

oidc apple 9

次に、Register を押します。

oidc apple 10

サービスリストに戻り、新しく作成したサービスをクリックします。

oidc apple 11

Sign in with Apple を有効にして、Configure を押します。

oidc apple 12

ドメインを追加して URL (<host>/_renarde/security/oidc-success に設定) を返し、Next を押します。

oidc apple 13

次に Done を押します。

oidc apple 14

続いて Continue を押します。

oidc apple 15

そして、Save を押します。

oidc apple 16

左側のメニューの Keys ページに移動し、+ を押します。

oidc apple 17

キー名を入力し、Sign in with Apple を有効にして、Configure を押します。

oidc apple 18

Primary App ID を選択し、Save を押します。

oidc apple 19

キーページに戻り、Continue を押します。

oidc apple 20

次に、Register を押します。

oidc apple 21

Key ID を書き留めてキーをダウンロードし、src/main/resources/AuthKey_<KEYID>.p8 の Quarkus アプリケーションに保存します。

oidc apple 22

これで、application.properties を設定できます。

quarkus.oidc.provider=apple
quarkus.oidc.client-id=<Bundle ID>
quarkus.oidc.credentials.jwt.key-file=AuthKey_<Key ID>.p8
quarkus.oidc.credentials.jwt.token-key-id=<Key ID>
quarkus.oidc.credentials.jwt.issuer=<App ID Prefix>
quarkus.oidc.credentials.jwt.subject=<Bundle ID}

quarkus.oidc.provider=apple will request Apple to add openid, email and name scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

Facebook

Facebook では、他のほとんどの OIDC プロバイダーのように localhost でアプリケーションをテストすることはできません。https で実行して公開する必要があるため、開発目的では https://ngrok.com などのサービスを使用することをお勧めします。

Facebook 用の OIDC を設定するには、 Creating an application から開始し、アプリのタイプとして None を選択して Next を押します。

oidc facebook 1

次に、アプリケーション名と連絡先のメールアドレスを入力し、Create app を押します。

oidc facebook 2

アプリページで、Facebook login 製品の Set up をクリックします。

oidc facebook 3

Quickstarts ページをクイックし、左側のメニューの Facebook login > Settings をクリックします。

oidc facebook 4

Redirect URIs を入力 (<host>/_renarde/security/oidc-success に設定) し、Save changes を押します:

oidc facebook 5

次に、左側のメニューの Settings > Basic に移動し、App IDApp secret を書き留めます。

oidc facebook 6

これで、application.properties を設定できます。

quarkus.oidc.provider=facebook
quarkus.oidc.client-id=<App ID>
quarkus.oidc.credentials.secret=<App secret>

quarkus.oidc.provider=facebook will request Facebook to add email and public_profile scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

Twitter

OIDC ログインには Twitter を使用できますが、現時点では、ユーザーのメールへのアクセスが制限されているため、ご自身で Twitter を取得して確認する必要があります。

Twitter 用の OIDC を設定するには、 Creating a project で開始し、プロジェクト名を入力して、Next を押します。

oidc twitter 1

ユースケースを入力し、Next を押します。

oidc twitter 2

プロジェクトの説明を入力し、Next を押します。

oidc twitter 3

次に、アプリケーション名を入力して、Next を押します。

oidc twitter 4

キーは再び表示されないので書き留めて、App Settings を押します。

oidc twitter 5

User authentication settings セクションに移動し、Set up を押します。

oidc twitter 6

OAuth 2.0 チェックボックスをオンにします。

oidc twitter 7

アプリケーションタイプとして Web App を選択し、アプリケーションの詳細を入力します (Callback URI の場合は <host>/_renarde/security/twitter-success を使用)。

Twitter は実際には https を使用する必要はありませんが、https がないと Website URL を受け入れないため、ngrok を引き続き使用できます。

次に、Save を押します。

oidc twitter 8

これで、Client ID および Client Secret をコピーして Done を押すことができます。

oidc twitter 9

これで、application.properties を設定できます。

quarkus.oidc.provider=twitter
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Client Secret>

quarkus.oidc.provider=twitter will request Twitter to add offline.access, tweet.read and users.read scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

Twitter provider requires Proof Key for Code Exchange (PKCE) which is supported by the quarkus.oidc.provider=twitter declaration. Quarkus has to encrypt the current PKCE code verifier in a state cookie while the authorization code flow with Twitter is in progress and it will generate a secure random secret key for encrypting it.

You can provide your own secret key for encrypting the PKCE code verifier if you prefer with the quarkus.oidc.authentication.state-secret property but note that this secret should be 32 characters long, and an error will be reported if it is less than 16 characters long.

X is a new name for Twitter, see X. You can continue using quarkus.oidc.provider=twitter but it might need to be changed to quarkus.oidc.provider=x in the future.

X

X is a new name for Twitter. You can currently use either quarkus.oidc.provider=x or quarkus.oidc.provider=twitter but only quarkus.oidc.provider=x may end up supported in the future.

Please see Twitter for more information about registering your Quarkus application in X (Twitter).

Spotify

Spotify application を作成します。

oidc spotify 1

開発目的のテスト用に、リダイレクト URI として http://localhost:8080 を追加することを忘れないでください。Spotify アプリケーションのセットアップが完了すると、クライアント ID とシークレットが生成されます。以下に例を示します。

oidc spotify 2

これで、application.properties を設定できます。

quarkus.oidc.provider=spotify
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.secret=<Client Secret>

quarkus.oidc.provider=spotiify will request Spotify to add user-read-private and user-read-email scopes to issued access tokens. For information about overriding these scopes or requesting more scopes, see the Provider scopes section.

Twitch

Create a Twitch application:

oidc twitch 1

これで、application.properties を設定できます。

quarkus.oidc.provider=twitch
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.client-secret.value=<Client Secret>

Provider scopes

Each provider declaration will request one or more token scopes added to access tokens issued by a given provider. For example, quarkus.oidc.provider=google will request Google to add openid, email and profile scopes.

You can override these scopes with quarkus.oidc.authentication.scopes property, for example, if you work with Google and would not like to have an email scope added to access tokens:

quarkus.oidc.provider=google
quarkus.oidc.authentication.scopes=oidc,profile

You may also want to add one or more scopes in addition to the scopes requested by default. For example, if you would like to use an access token issued by Google to access Google Calendar service, you can do it like this:

quarkus.oidc.provider=google
quarkus.oidc.authentication.extra-params.scope=https://www.googleapis.com/auth/calendar

It is simpler than using quarkus.oidc.authentication.scopes to add a new scope, because quarkus.oidc.authentication.scopes overrides the scopes already set by the provider declaration, which is why you need to list all the required scopes in this case:

quarkus.oidc.provider=google
quarkus.oidc.authentication.scopes=oidc,email,profile,https://www.googleapis.com/auth/calendar

Support for multiple providers

If you would like to support authenticating users with more than one provider then a provider-specific tenant configuration resolution must be supported.

For more information, see the Quarkus Using OpenID Connect (OIDC) Multi-Tenancy guide.

Access provider services with token propagation

Sometimes, only authenticating users with a social provider is not enough. A provider-specific service also needs to be accessed for the Quarkus OIDC web-app application to fetch or update data from the provider service on behalf of the currently authenticated user.

As mentioned in the OIDC code flow mechanism for protecting web applications guide, ID and access tokens are returned after the authorization code flow has been completed, with some providers like GitHub returning an access token only. It is this access token that has to be propagated to services such as Google Calendar, or Spotify Playlists for the currently authenticated user to be able to use such services.

You do not have to bring provider-specific libraries in order to achieve this, but instead you can use a reactive Token Propagation filter, which can be bound to a given REST client with a simple annotation. For more information, see the Quarkus Access token propagation guide.

For example, after you have configured the Google provider, you can have events added to the user’s Google Calendar by using a REST client as shown in the following example:

package org.acme.calendar;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.oidc.token.propagation.AccessToken;
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@RegisterRestClient(configKey="google-calendar-api")
@AccessToken  (1)
@Path("/calendars/primary")
public interface GoogleCalendarClient {
    @POST
    @Path("events")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    Uni<String> addEvent(Event event);
    public static class Event {
        public String summary;
        public String kind = "calendar#event";
        public Time start;
        public Time end
    }

    public static class Time {
        public String dateTime;
        public String timeZone = "Europe/CET";
        public Time() {
        }
        public Time(String value) {
            dateTime = value;
	}
    }
}
1 The @AccessToken annotation enables an access token propagation to the target service.

Finally, you need to configure the Google Calendar address and request the Google Calendar scope for an access token, as outlined in the following example:

quarkus.oidc.authentication.extra-params.scope=https://www.googleapis.com/auth/calendar
quarkus.rest-client.google-calendar-api.url=https://www.googleapis.com/calendar/v3

HTTPS Redirect URL

Some providers will only accept HTTPS-based redirect URLs. Tools such as ngrok can be set up to help testing such providers with Quarkus endpoints running on localhost in devmode.