OAuth クライアントの登録
OAuth クライアントまたはサード・パーティー・サービス・アプリケーションは、WebSphere® Application Server OAuth2 サービス・プロバイダーに自分自身を登録する必要があります。 登録されたクライアントは、XML ファイルとして保管されるか、またはデータベース表に保管されます。
登録されたクライアントを XML ファイルとして保管するには、base.clients.xml という XML ファイルを作成します。 この XML ファイルは、WebSphere Application Server セル・ディレクトリーまたはノード・ディレクトリー内の oauth20 ディレクトリーの下に置く必要があります。 サンプルの base.clients.xml ファイルが WebSphere Application Server インストールの properties ディレクトリーにあります。
登録されたクライアントをデータベース表に保管するには、次の表作成 SQL ステートメントを使用します。
/*Client Table*/
CREATE TABLE OAuthDBSchema.OAUTH20CLIENTCONFIG (
COMPONENTID VARCHAR(256) NOT NULL, /*Name of OAuth Provider and matches config.xml*/
CLIENTID VARCHAR(256) NOT NULL, /*ID of client*/
CLIENTSECRET VARCHAR(256), /*Client secret*/
DISPLAYNAME VARCHAR(256) NOT NULL, /*Display name of the client*/
REDIRECTURI VARCHAR(2048), /*client redirect URI*/
ENABLED INT /*int*/
);
クライアントを保管するファイルおよび表を作成したならば、その後はクライアントを直接に追加、削除、または変更することができます。 また、WebSphere Application Server MBean またはプログラミング API を使用してクライアントを管理することもできます。
次の例は、クライアント API を使用したクライアント管理のサンプル・コードを示しています。
import com.ibm.ws.security.oauth20.plugins.BaseClientProvider;
import com.ibm.ws.security.oauth20.plugins.BaseClient;
import com.ibm.ws.security.oauth20.api.OAuth20Provider;
import com.ibm.ws.security.oauth20.api.OAuth20ProviderFactory;
import com.ibm.ws.security.oauth20.plugins.db.CachedDBClientProvider;
OAuth20Provider provider = OAuth20ProviderFactory.getOAuth20Provider("<<provider_name>>");
OAuthComponentConfiguration oauthconfig = provider.getConfiguration();
CachedDBClientProvider clientProvider = new CachedDBClientProvider(); //if using Database for client store
//BaseClientProvider clientProvider = new BaseClientProvider(); //if using XML file for client store
clientProvider.init(oauthconfig);
// replace << .... >> with desired String
BaseClient newClient = new BaseClient(oauthconfig.getUniqueId(),
"<<client_id>>",
"<<client_secret>>",
"<<client displayName>>",
"<<redirect uri>>",
true);
//add a new client
clientProvider.put(newClient);
//delete a client
clientProvider.delete("<<client_id>>");
//query all registered clients
Collection<BaseClient> clients = clientProvider.getAll();
for (BaseClient client : clients) {
String client_display_name = client.getDisplayName();
String client_id = client.getClientId();
String redirect_uri = client.getRedirectUri();
}
次の例は、MBean API を使用したクライアント管理のサンプル・コードを示しています。
//get OAuth client mBean OAuth20ClientMBean
ObjectName objName = new ObjectName ("WebSphere:type=OAuth20ClientMBean,*");
AdminClient adminClient = ....;
// add a new client
BaseClient newClient = new BaseClient(oauthconfig.getUniqueId(),
"<<<<client_id>>",
"<<client_secret>>",
"<<client displayName>>",
"<<redirect uri>>",
true);
adminClient.invoke(objName,
"addClient",
new Object[]{newClient},
new String[]{newClient.getClass().getName()});
//delete a client by client id
adminClient.invoke(objName,
"removeClient",
new Object[]{providerName, "<<client id>>"},
new String[]{providerName.getClass().getName(),
clientName.getClass().getName()});