Token Binding makes it easy to get OAuth Access Token provided by Azure Active Directory

★★★ お知らせ ★★★

◆ 6月のPS Liveは決済サービスStripeのデモ!◆
決済サービスのStripeでサブスクリプションの支払い機能を作ってみた
Stripeの機能の一部を切り出して、簡単なサブスクリプションを作るとどうなるのかを、デモをまじえてご紹介します。
⇒ 詳細はこちらから

◆【セミナー開催】 可視化ツールGrafana~初めてのダッシュボード作成◆
デモンストレーション付き!
本セミナーでは、売上データを用いて、4種類のパネル作成方法をお見せします。
⇒ お申込みはこちらから

◆ エンジニア業務環境アンケート結果 ◆
エンジニアが自分の働き方にどういったことで満足していて、不満を感じているのか、働きたい会社像として何を求めているのか、業務環境調査を実施しました。ぜひご覧ください。
⇒ アンケート結果はこちらから

To access Office365 Service such as Exchange, it’s useful to use Graph API.Graph API requires OAuth Access Token provided by Azure Active Directory.But id’s so difficult to treat OAuth.At first, we need to get authorization code by accessing authorization code to Authorization Endpoint and to generate Access Token by passing  authorization code to Token Endpoint.In Addition, when access token got expired, regenerating Access Token by Refresh Token is required.

Token Binding saves the efforts to do many steps above-mentioned.Token Binding is a kind of HTTP Trigger Binding, Queue Trigger Binding and so on.

Let’s get started.I’ll try this by publishing C# code to Azure Portal from Visual Studio.

In this case, I assume that the registration of App to Azure Active Directory has been already completed.

At first, access Azure Functions Settings, click “Platform features” and  click “Authentication / Authorization”.

Screen Shot 2019-02-07 at 23.03.02

 

Switch on “App Service Authentication” and click “Azure Active Directory” located below “Authentication Provider”.

Screen Shot 2019-02-07 at 23.07.00

 

In this case, Azure Active Directory which manages Azure differs from one which manages Office365.Click “Advanced”, type Client ID of Application registered to Azure Active Directory to “Client ID”,  type Client Secret of Application registered to Azure Active Directory to “Client Secret”, type ”https://sts.windows.net/[TenantID]’ to “Issuer Uri”, and the click “OK”.

Screen Shot 2019-02-07 at 23.08.53

 

To use Token Binding, installing some libraries is required.Install “Microsoft.Azure.Webjobs.Extensions.AuthTokens” by NuGet Package Manager in Visual Studio.

See the following code which use Token Binding.

The following statement enables Token Binding.OAuth Access Token is set to the variable “graphToken“.

[Token(IdentityProvider = AAD, Resource = https://graph.microsoft.com/, Identity = TokenIdentityMode.ClientCredentials)]string graphToken

Publish this code to Azure Portal and execute one.You can see Access Token displayed after “Access Token:“.

 

アバター画像
About 武井 宜行 251 Articles
Microsoft MVP for Azure🌟「最新の技術を楽しくわかりやすく」をモットーにブログtech-lab.sios.jp)で情報を発信🎤得意分野はAzureによるクラウドネイティブな開発(Javaなど)💻「世界一わかりみの深いクラウドネイティブ on Azure」の動画を配信中📹 https://t.co/OMaJYb3pRN
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる