OAuth を使用した IMAP、POP、SMTP または Exchange 接続の認証

OAuth を使用して IMAP、POP、SMTP および Exchange 接続を認証するのに役立つ修正が ColdFusion(2021 リリース)および ColdFusion(2018 リリース)向けにリリースされました。

このアップデートの適用方法

このアップデートを適用する前に、ColdFusion のどちらのバージョンにも最新のアップデートが適用されていることを確認してください。

メモ

ColdFusion インスタンスが複数ある場合は、インスタンスごとにアップデートを適用する必要があります。

ColdFusion(2021 リリース)

  1. patch.zip ファイルを解凍します。
  2. ColdFusion サーバーを停止します。
  3. <cf_home>/cfusion/bundles/mail-2021.0.05.330109.jar を mail-2021.0.05.330109.jar ファイルに置き換えます。
  4. <cf_home>/cfusion/lib/mail.jar を mail.jar に置き換えます。
  5. <cf_home>/cfusion/bin/felix-cache フォルダーをクリアします。
  6. jvm.config にフラグ -Dcoldfusion.mail.oauth2=true を追加します。
  7. ColdFusion サーバーを起動します。

ColdFusion(2018 リリース)

  1. ColdFusion サーバーを停止します。
  2. hf201800-4212004.jar ファイルを C:\ColdFusion2018\cfusion\lib\updates にコピーします。
  3. <cf_home>/cfusion/lib/ を mail.jar ファイルに置き換えます。
  4. jvm.config にフラグ -Dcoldfusion.mail.oauth2=true を追加します。
  5. ColdFusion サーバーを起動します。

認証コードを取得します。

アプリケーションの登録

OAuth を使用するには、アプリケーションを Azure Active Directory に登録します。詳しくは、クイックスタート:Microsoft ID プラットフォームにアプリケーションを登録するを参照してください。clientid、secretkey、authendpoint は、アプリケーションの登録後に取得されます。

アクセストークンの取得

SMTP

認証コードを取得します。

<cfoauth
    clientid = &quot;client-id&quot; 
    secretkey = &quot;secret-key&quot; 
    scope=&quot;https://outlook.office.com/SMTP.Send&quot; 
    authendpoint=&quot;auth-end-point&quot; 
    accesstokenendpoint = &quot;access-token-endpoint&quot; 
    result = &quot;res&quot; 
    redirecturi = &quot;http://localhost:8500/oauth/response.cfm&quot;> 

アクセストークンを取得します。

<cfhttp result=&quot;res&quot; url=&quot;https://login.microsoftonline.com/<auth-code>/oauth2/v2.0/token&quot; method=&quot;post&quot;>
	<cfhttpparam name=&quot;grant_type&quot; type=&quot;formfield&quot; value=&quot;authorization_code&quot;> 
	<cfhttpparam name=&quot;code&quot; type=&quot;formfield&quot; value=&quot;#code#&quot;> 
	<cfhttpparam name=&quot;client_id&quot; type=&quot;formfield&quot; value=&quot;client-id&quot;> 
	<cfhttpparam name=&quot;scope&quot; type=&quot;formfield&quot; value=&quot;https://outlook.office.com/SMTP.Send&quot;> 
	<cfhttpparam name=&quot;client_secret&quot; type=&quot;formfield&quot; value=&quot;secret-key&quot;> 
	<cfhttpparam name=&quot;redirect_uri&quot; type=&quot;formfield&quot; value=&quot;http://localhost:8500/oauth/response.cfm&quot;> 
</cfhttp> 
<cfset record=deserializeJSON(res.Filecontent)/> 
<cfset token=#record.access_token#/> 

アクセストークンを cfmail の password フィールドに渡します。

<cfmail server=&quot;smtp.office365.com&quot; to=&quot;username@example.com&quot; from=&quot;username@example.com&quot; subject=&quot;#emailid#&quot; port=&quot;587&quot; username=&quot;#username#&quot; 
		password=&quot;#token#&quot; spoolenable=false useTLS=true timeout=120> 

	Hello, World! 
</cfmail> 

POP

認証コードを取得します。

<cfoauth
    clientid = &quot;client-id&quot; 
    secretkey = &quot;secret-key&quot; 
    scope=&quot;https://outlook.office.com/POP.AccessAsUser.All&quot; 
    authendpoint=&quot;auth-end-point&quot; 
    accesstokenendpoint = &quot;access-token-endpoint&quot; 
    result = &quot;res&quot; 
    redirecturi = http://localhost:8500/oauth/response.cfm> 

アクセストークンを取得します。

<cfhttp result=&quot;res&quot; url=&quot;https://login.microsoftonline.com/<auth-code>/oauth2/v2.0/token&quot; method=&quot;post&quot;>
	<cfhttpparam name=&quot;grant_type&quot; type=&quot;formfield&quot; value=&quot;authorization_code&quot;> 
	<cfhttpparam name=&quot;code&quot; type=&quot;formfield&quot; value=&quot;#code#&quot;> 
	<cfhttpparam name=&quot;client_id&quot; type=&quot;formfield&quot; value=&quot;client-id&quot;> 
	<cfhttpparam name=&quot;scope&quot; type=&quot;formfield&quot; value=&quot;https://outlook.office.com/POP.Send&quot;> 
	<cfhttpparam name=&quot;client_secret&quot; type=&quot;formfield&quot; value=&quot;secret-key&quot;> 
	<cfhttpparam name=&quot;redirect_uri&quot; type=&quot;formfield&quot; value=&quot;http://localhost:8500/oauth/response.cfm&quot;> 
</cfhttp> 
<cfset record=deserializeJSON(res.Filecontent)/> 
<cfset token=#record.access_token#/> 

アクセストークンを cfpop の password フィールドに渡します(下記を参照)。

<cfpop server = &quot;outlook.office365.com&quot; username = &quot;#username#&quot; password=&quot;#token#&quot; port=&quot;995&quot; action=&quot;GETALL&quot; name=&quot;msg&quot; secure=&quot;true&quot;>

IMAP

認証コードを取得します。

<cfoauth
    clientid = &quot;client-id&quot; 
    secretkey = &quot;secret-key&quot; 
    scope=&quot;https://outlook.office.com/IMAP.AccessAsUser.All&quot; 
    authendpoint=&quot;auth-end-point&quot; 
    accesstokenendpoint = &quot;access-token-endpoint&quot; 
    result = &quot;res&quot; 
    redirecturi = http://localhost:8500/oauth/response.cfm> 

アクセストークンを取得します。

<cfhttp result=&quot;res&quot; url=&quot;https://login.microsoftonline.com/<auth-code>/oauth2/v2.0/token&quot; method=&quot;post&quot;>
	<cfhttpparam name=&quot;grant_type&quot; type=&quot;formfield&quot; value=&quot;authorization_code&quot;> 
	<cfhttpparam name=&quot;code&quot; type=&quot;formfield&quot; value=&quot;#code#&quot;> 
	<cfhttpparam name=&quot;client_id&quot; type=&quot;formfield&quot; value=&quot;client-id&quot;> 
	<cfhttpparam name=&quot;scope&quot; type=&quot;formfield&quot; value=&quot;https://outlook.office.com/IMAP.Send&quot;> 
	<cfhttpparam name=&quot;client_secret&quot; type=&quot;formfield&quot; value=&quot;secret-key&quot;> 
	<cfhttpparam name=&quot;redirect_uri&quot; type=&quot;formfield&quot; value=&quot;http://localhost:8500/oauth/response.cfm&quot;> 
</cfhttp> 
<cfset record=deserializeJSON(res.Filecontent)/> 
<cfset token=#record.access_token#/> 

アクセストークンを cfimap の password フィールドに渡します(下記を参照)。

<cfimap action=&quot;OPEN&quot; connection=&quot;IMAPCONNECTION&quot; server=&quot;outlook.office365.com&quot; 
        username=&quot;#username#&quot; password=&quot;#token#&quot; secure=&quot;true&quot; stoponerror=&quot;false&quot;/>

<cfimap action=&quot;LISTALLFOLDERS&quot; connection=&quot;IMAPCONNECTION&quot; name=&quot;queryname&quot; recurse=true stoponerror=&quot;false&quot;/>

cfexchange のアップデートの適用

アップデートの適用方法を以下に示します。

ColdFusion(2021 リリース)

  1. exchange パッケージ JAR ファイルをダウンロードします。
  2. ColdFusion サーバーを停止します。
  3. <cf_home>/cfusion/bundles/exchange-2021.0.05.330109.jar を exchange-2021.0.05.330109.jar ファイルに置き換えます。
  4. C:\ColdFusion2021\cfusion\bin\felix-cache フォルダーをクリアします。
  5. jvm.config ファイルに jvm の引数「-Dcoldfusion.exchange.useOauth2=true」を設定します(デフォルトは false)。
  6. ColdFusion サーバーを起動します。

ColdFusion(2018 リリース)

  1. ColdFusion サーバーを停止します。
  2. hf201800-4212511.jar ファイルを <cf_home>/cfusion/lib/updates にコピーします。
  3. jvm.config ファイルに jvm の引数「-Dcoldfusion.exchange.useOauth2=true」を設定します(デフォルトは false)。
  4. ColdFusion サーバーを起動します。

認証済みの exchange 接続を取得するために cfexchangeconnection に渡すことができるアクセストークンを次のワークフローで生成します。

<cfoauth
	clientid = &quot;your clientid&quot;
	secretkey = &quot;secret created in Azure portal when registering the application&quot;
	scope = &quot;https://outlook.office365.com/EWS.AccessAsUser.All&quot;
	authendpoint = &quot;https://login.microsoftonline.com/<tenant-ID>/oauth2/v2.0/authorize&quot;
	accesstokenendpoint = &quot;https://login.microsoftonline.com/<tenant-ID>/v2.0/token&quot;
	result = &quot;oresult&quot;
	redirecturi = &quot;http://localhost:8500/oauth/response.cfm&quot;>

response.cfm

<cfhttp result=&quot;httpresult&quot; url=&quot;https://login.microsoftonline.com/<tenant-ID>/oauth2/v2.0/token&quot; method=&quot;post&quot;>
	<cfhttpparam name=&quot;grant_type&quot; type=&quot;formfield&quot; value=&quot;authorization_code&quot;>
	<cfhttpparam name=&quot;scope&quot; type=&quot;formfield&quot; value=&quot;https://outlook.office365.com/EWS.AccessAsUser.All&quot;>
	<cfhttpparam name=&quot;code&quot; type=&quot;formfield&quot; value=&quot;#url.code#&quot;>
	<cfhttpparam name=&quot;client_id&quot; type=&quot;formfield&quot; value=&quot;your clientid&quot;>
	<cfhttpparam name=&quot;redirect_uri&quot; type=&quot;formfield&quot; value=&quot;http://localhost:8500/oauth/response.cfm&quot;>
</cfhttp>
<cfdump var=#res.Filecontent#> // この応答内の access_token には cfexchange タグに渡された access_token が含まれている

<cfexchangeconnection action=&quot;open&quot;
	username=&quot;username@domain.com&quot;	
	password=&quot;#auth-token#&quot;
	server=&quot;outlook.office365.com&quot;
	protocol=&quot;https&quot;
	serverversion=&quot;2010_SP2&quot;
	connection=&quot;exchangeconn&quot;>

別のユーザーとして実行する場合は、-Dcoldfusion.exchange.setImpersonatedUser=true
のようにフラグを true に設定します(デフォルトは false)。

Adobe, Inc.

ヘルプをすばやく簡単に入手

新規ユーザーの場合