Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Gen1 DocsLegacy

Page updated Jun 20, 2024

OpenID Connectを認可プロバイダーとして使用する

プライベート、オーナー、およびグループ認可は、OpenID Connect(OIDC)認可モードで設定できます。認可ルールにプロバイダーとして"oidc"を追加します。oidcAuthorizationModeプロパティを使用して、OpenID Connectプロバイダー名OpenID ConnectプロバイダードメインClient IDIssued at TTL、およびAuth Time TTLを設定します。

以下の例は、oidc認可プロバイダーでサポートされている認可戦略を強調しています。オーナーおよびグループベースの認可の場合、カスタム ID とグループクレームを指定する必要があります。

amplify/data/resource.ts
// amplify/data/resource.ts
import { a, defineData, type ClientSchema } from '@aws-amplify/backend';
const schema = a.schema({
Todo: a
.model({
content: a.string(),
})
.authorization(allow => [
allow.owner('oidc').identityClaim('user_id'),
allow.authenticated('oidc'),
allow
.groups(['testGroupName'], 'oidc')
.withClaimIn('user_groups'),
]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: 'oidc',
oidcAuthorizationMode: {
oidcProviderName: 'oidc-provider-name',
oidcIssuerUrl: 'https://example.com',
clientId: 'client-id',
tokenExpiryFromAuthInSeconds: 300,
tokenExpireFromIssueInSeconds: 600,
},
},
});

アプリケーションでは、client.models.<model-name>を使用してoidc認可モードを指定し、モデルに対してCRUD操作を実行できます。

import { generateClient } from 'aws-amplify/data';
import type { Schema } from '../amplify/data/resource'; // Path to your backend resource definition
const client = generateClient<Schema>();
const { errors, data: todos } = await client.models.Todo.list({
authMode: "oidc",
});