Authlete
|
Authlete Web APIs のための C# ライブラリです。
Authlete は OAuth 2.0 と OpenID Connect の実装を提供するクラウドサービスです。 Authlete が提供する Web API を使い、DB-less (データベース無し) の認可サーバーを構築することができます。「DB-less」とは、認可データ (アクセストークン等)、 認可サーバーの設定、クライアントアプリケーションの設定を保存するデータベースを管理する必要が無い、という意味です。 これらのデータはクラウド上にある Authlete サーバーに保存されます。
Authlete のアーキテクチャーの詳細については、 New Architecture of OAuth 2.0 and OpenID Connect Implementation をお読みください。真のエンジニアであれば、このアーキテクチャーを気に入ってくれるはずです ;-) なお、日本語版は「OAuth 2.0 / OIDC 実装の新アーキテクチャー」です。
The primary advantage of this architecture is in that the backend service can focus on implementing OAuth 2.0 and OpenID Connect without caring about other components such as identity management, user authentication, login session management, API management and fraud detection. And, consequently, it leads to another major advantage which enables the backend service (implementation of OAuth 2.0 and OpenID Connect) to be combined with any solution of other components and thus gives flexibility to frontend server implementations.
このアーキテクチャーの一番の利点は、アイデンティティー管理やユーザー認証、 ログインセッション管理、API 管理、不正検出などの機能について気にすることなく、 バックエンドサービスが OAuth 2.0 と OpenID Connect の実装に集中できることにあります。 この帰結として、バックエンドサービス (OAuth 2.0 と OpenID Connect の実装) をどのような技術部品とも組み合わせることが可能というもう一つの大きな利点が得られ、 フロントエンドサーバーの実装に柔軟性がもたらされます。
Apache License, Version 2.0
https://github.com/authlete/authlete-csharp
https://authlete.github.io/authlete-csharp/
Authlete Web API とやりとりするメソッドは全て IAuthleteApi
インターフェースに集められています。 現在のところ、このインターフェースを実装するクラスは AuthleteApi
クラスのみです。
AuthleteApi
クラスのコンストラクターは IAuthleteConfiguration
インターフェースの実装を要求します。 IAuthleteConfiguration
インタフェースの実装が用意できれば、次のようにして AuthleteApi
のインスタンスを作成することができます。
IAuthleteConfiguration
は、Authlete サーバーの URL やサービスの API クレデンシャルズなどの、Authlete Web API にアクセスするのに必要な設定値を保持するインターフェースです。 具体的には、このインターフェースには次のようなプロパティー群があります。
プロパティー | 説明 |
---|---|
BaseUrl | Authlete サーバーの URL |
ServiceApiKey | サービスの API キー |
ServiceApiSecret | サービスの API シークレット |
ServiceOwnerApiKey | あなたのアカウントの API キー |
ServiceOwnerApiSecret | あなたのアカウントの API シークレット |
authlete-csharp には IAuthleteConfiguration
インターフェースの実装が三つ含まれています。
クラス | 説明 |
---|---|
AuthleteEnvConfiguration | 環境変数による設定 |
AuthletePropertiesConfiguration | プロパティーファイルによる設定 |
AuthleteSimpleConfiguration | C# プロパティーによる設定 |
IAuthleteConfiguration
インターフェースの三つの実装のうち、ここでは AuthletePropertiesConfiguration
クラスについて説明します。
AuthletePropertiesConfiguration
クラスは、Authlete Web API へのアクセスに必要な設定をプロパティーファイルでおこなう仕組みを提供します。 ここでいうプロパティーファイルとは、Java の世界で用いられる設定ファイルの一種です。 ファイルフォーマットの仕様は java.util.Properties.load(java.io.Reader)
の JavaDoc に記述されています。 authlete-csharp には、プロパティーファイルフォーマットを解釈する実装 (Authlete.Util.Properties
) が含まれています。
AuthletePropertiesConfiguration
には三つのコンストラクターがあります。 下記はそれらの使用例です。
AuthletePropertiesConfiguration
クラスは、与えられた設定ファイル内に次の項目があることを期待しています。
プロパティーキー | 説明 |
---|---|
base_url | Authlete サーバーの URL |
service.api_key | サービスの API キー |
service.api_secret | サービスの API シークレット |
service_owner.api_key | あなたのアカウントの API キー |
service_owner.api_secret | あなたのアカウントの API シークレット |
下記は設定ファイルの例です。
IAuthleteApi
の Settings
プロパティーは ISettings
インターフェースの実装を返します。 これを介して IAuthleteApi
インターフェースの実装の動作を調整することができます。
IAuthleteApi
インターフェースのメソッド群は幾つかのカテゴリーに分けることができます。
Authorization(AuthorizationRequest request)
AuthorizationFail(AuthorizationFailRequest request)
AuthorizationIssue(AuthorizationIssueRequest request)
Token(TokenRequest request)
TokenFail(TokenFailRequest request)
TokenIssue(TokenIssueRequest request)
CreateService(Service service)
DeleteService(long serviceApiKey)
GetService(long serviceApiKey)
GetServiceList()
GetServiceList(int start, int end)
UpdateService(Service service)
CreateClient(Client client)
DeleteClient(long clientId)
GetClient(long clientId)
GetClientList()
GetClientList(string developer)
GetClientList(int start, int end)
GetClientList(string developer, int start, int end)
UpdateClient(Client client)
RefreshClientSecret(long clientId)
RefreshClientSecret(string clientIdentifier)
UpdateClientSecret(long clientId, string clientSecret)
UpdateClientSecret(string clientIdentifier, string clientSecret)
Introspection(IntrospectionRequest request)
StandardIntrospection(StandardIntrospectionRequest request)
Revocation(RevocationRequest request)
Userinfo(UserInfoRequest request)
UserinfoIssue(UserInfoIssueRequest request)
GetServiceJwks()
GetServiceJwks(bool pretty, bool includePrivateKeys)
GetServiceConfiguration()
GetServiceConfiguration(bool pretty)
TokenCreate(TokenCreateRequest request)
TokenDelete(string token)
TokenUpdate(TokenUpdateRequest request)
GetGrantedScopes(long clientId, string subject)
DeleteGrantedScopes(long clientId, string subject)
DeleteClientAuthorization(long clientId, string subject)
GetClientAuthorizationList(ClientAuthorizationGetListRequest request)
UpdateClientAuthorization(long clientId, ClientAuthorizationUpdateRequest request)
BackchannelAuthentication(BackchannelAuthenticationRequest request)
BackchannelAuthenticationIssue(BackchannelAuthenticationIssueRequest request)
BackchannelAuthenticationFail(BackchannelAuthenticationFailRequest request)
BackchannelAuthenticationComplete(BackchannelAuthenticationCompleteRequest request)
DeviceAuthorization(DeviceAuthorizationRequest request)
DeviceComplete(DeviceCompleteRequest request)
DeviceVerification(DeviceVerificationRequest request)
PushAuthorizationRequest(PushedAuthReqRequest request)
例
次のコードは既存のサービスのリストを取得する例です。 各サービスは一つの認可サーバーに対応します。
IAuthleteApi
インターフェースのメソッド群だけを用いて認可サーバーや OpenID プロバイダーを開発することも可能ですが、Authlete.Handler
名前空間にあるユーティリティークラス群を用いることで、作業はもっと簡単になります。
ハンドラーの使用例の使用例は csharp-oauth-server と cshar-resource-server にあります。 これらは認可サーバーとリソースサーバーのサンプル実装です。 『C# による OAuth 2.0 と OpenID Connect の実装 (Authlete)』 はこれらの二つのサンプルサーバーに関する記事です。
$ cd Authlete.Tests $ dotnet test
CHANGES.md
と CHANGES.ja.md
を更新する。 必要があれば README.md
と README.ja.md
も更新する。
Visual Studio で Authlete
プロジェクトの「オプション」メニューを開く。 「プロジェクト オプション - Authlete」というタイトルのウィンドウで、 「NuGet パッケージ」→「メタデータ」→「全般」タブ、と進む。 「バージョン:」欄の値を更新する。
もしくは、Authlete/Authlete.csproj
ファイル内の <PackageVersion>
の値を直接更新する。
$ git add Authlete/Authlete.csproj $ git commit -m 'Updated PackageVersion to X.Y.Z.' $ git push
$ dotnet pack
bin/Debug
ディレクトリに .nupkg
ファイルが生成される。
$ nuget push bin/Debug/Authlete.Authlete.X.Y.Z.nupkg $KEY \ -Source https://api.nuget.org/v3/index.json
コマンドライン上の $KEY
の値は nuget.org から発行された API キー。 詳細は『Publishing packages』を参照のこと。
公開されたパッケージは https://www.nuget.org/packages/Authlete.Authlete にリストされるが、何分か時間がかかる。
$ cd .. $ rm -rf html $ doxygen
$ mkdir -p ../docs $ cd ../docs $ git clone https://github.com/authlete/authlete-csharp $ cd authlete-csharp $ git checkout gh-pages $ rm -rf * $ cp -r ../../authlete-csharp/html/* . $ git add . $ git commit -m 'Updated for version X.Y.Z' $ git push origin gh-pages
目的 | メールアドレス |
---|---|
一般 | info@ auth lete. com |
営業 | sales @aut hlete .com |
広報 | pr@au thle te.co m |
技術 | suppo rt@a uthle te.c om |