invalid_request: Unexpected client assertion type, when using certificates based authorization
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- php
- 領域
- api, authentication
調査の方向性
AuthorizationCodeCertificateContext、InMemoryAccessTokenCache、GraphPhpLeagueAccessTokenProviderから始め、次にレポートに示されているrefresh tokenリクエストを追跡します。証明書ベースのrefresh動作を、正常に動作するsecretベースのフローと比較します。保存されたrefresh tokenでAADSTS90023を発生させずにaccess tokenを更新できれば、問題は解決です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Hello, I'm trying to use certificates (self-signed) based authorization for getting access tokens on behalf of user (their outlook calendar resources).
I'm using AuthorizationCodeCertificateContext to acquire initial access and refresh tokens, then I store them in db for later usage.
Using stored access token works well until it expires, when I get invalid_request error when sdk tries to refresh access token, again using stored refresh token
I'm not sure how am I able to get access and refresh tokens using AuthorizationCodeCertificateContext, then use access token successfully to fetch some user resources, but not able to refresh access token.
Expected behavior
If I understand token management correctly, expected behavior should be that refreshing token just works out of the box if I provide refresh token to InMemoryAccessTokenCache.
I tried same thing using secrets instead of certificates, it works as expected.
Also checked if sdk actually is trying to refresh token and is sending proper request, it should be okay as well:
method: POST
url: https://login.microsoftonline.com/{my-tenant-id}/oauth2/v2.0/token
headers: [
"content-type" => "application/x-www-form-urlencoded"
]
body:
"client_id" => "abc"
"grant_type" => "refresh_token"
"client_assertion" => "eyJ0eXAiOiJKV1QiLCJ4NXQiOiJXUklac2RPRE9WaHlxTWFoQ2VfYUxnTHdGTE0iLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vZTU0OGZkOWQtZmJmZC0..."
"client_assertion_type" => "urn:ietf:params:Oauth:client-assertion-type:jwt-bearer"
"refresh_token" => "1.AR8Anf1I5f372U6UbFh_vPA_wn8-2g2i6gpHmbfGx5rrSzccAfUfAA.AgABAwEAAABVrSpeuWamRam2jAF1XRQEAwDs_..."
How to reproduce
this is how I created self-signed CA:
$privateKeyOptions = [
'digest_alg' => OPENSSL_ALGO_SHA256,
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
];
// Generate a new private key
$privateKey = openssl_pkey_new($privateKeyOptions);
if ($privateKey === false) {
throw new RuntimeException(sprintf('Failed to generate private key: %s', openssl_error_string()));
}
// Generate a certificate signing request
$csr = openssl_csr_new([
'countryName' => 'xx',
'stateOrProvinceName' => 'xxxx',
'localityName' => 'xx',
'organizationName' => 'xx',
'commonName' => 'localhost',
], $privateKey, $privateKeyOptions);
if (is_bool($csr)) {
throw new RuntimeException(sprintf('Failed to open RSA key: %s', openssl_error_string()));
}
// Generate a self-signed certificate valid for 1 year
$certificate = openssl_csr_sign(
csr: $csr,
ca_certificate: null,
private_key: $privateKey,
days: CertificateRotatorInterface::MAX_DURATION_IN_DAYS
);
if ($certificate === false) {
throw new RuntimeException(sprintf('Failed to sign data: %s', openssl_error_string()));
}
// Export the certificate and key to files
$certificateFilePath = '/tmp/tls_crt.pem';
$privateKeyFilePath = '/tmp/tls_key.pem';
if (!openssl_x509_export_to_file($certificate, $certificateFilePath)) {
throw new RuntimeException(sprintf('Failed to export certificate: %s', openssl_error_string()));
}
if (!openssl_pkey_export_to_file($privateKey, $privateKeyFilePath)) {
throw new RuntimeException(sprintf('Failed to export private key: %s', openssl_error_string()));
}
tls_crt.pem file is uploaded through Microsoft Entra Admin to an application I registered for testing.
GraphServiceClient setup:
(I use "code_verifier" while getting authorization code, here it's just some placeholder value)
$tokenRequestContext = new AuthorizationCodeCertificateContext(
tenantId: $tenantId,
clientId: $clientId,
authCode: 'default',
redirectUri: $redirectUri,
certificatePath: $certificatePath,
privateKeyPath: $privateKeyPath,
additionalParams: ['code_verifier' => 'default']
);
$inMemoryCache = new InMemoryAccessTokenCache(
$tokenRequestContext,
new AccessToken([
'access_token' => $token['accessToken'],
'refresh_token' => $token['refreshToken'],
'expires' => $token['expires'],
])
);
$graphServiceClient = GraphServiceClient::createWithAuthenticationProvider(
GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
GraphPhpLeagueAccessTokenProvider::createWithCache(
$accessTokenCache,
$tokenRequestContext,
$scopes
)
)
);
dump($graphServiceClient->me()->get()->wait());
SDK Version
2.30.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
League\OAuth2\Client\Provider\Exception\IdentityProviderException {
#response: array:6 [
"error" => "invalid_request"
"error_description" => "AADSTS90023: Unexpected client assertion type. Trace ID: a0dfae09-fd6a... Correlation ID: ae87cdb5-9cb1-4a43... Timestamp: 2025-03-24 14:15:17Z "
"error_codes" => array:1 [
0 => 90023
]
"timestamp" => "2025-03-24 14:15:17Z"
"trace_id" => "a0dfae09-fd6a-482f..."
"correlation_id" => "ae87cdb5-9cb1-4a43..."
]
}
Configuration
docker base image: php:8.4-fpm-alpine3.21
Other information
No response
- 主要言語
- PHP
- スター
- 669
- フォーク
- 149
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoftgraph/msgraph-sdk-php のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoftgraph/msgraph-sdk-php#1794 · コメント 2 件 ·
-
bug: metadata type:bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
microsoftgraph/msgraph-sdk-php#1739 · コメント 6 件 ·
-
status:waiting-for-triage type:bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
microsoftgraph/msgraph-sdk-php#1643 · コメント 8 件 · リアクション 4 件 ·
-
status:waiting-for-triage
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoftgraph/msgraph-sdk-php#1800 · リアクション 3 件 ·
-
Nowオープン
難易度 5/5 1週間以上 初心者へのやさしさ 1/100
microsoftgraph/msgraph-sdk-php#1799 ·
microsoftgraph/msgraph-sdk-php の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
matomo-org/plugin-CustomAlerts#310 ·
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
domain/checkout Platform(Default) priority/low testing/acceptance
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
pluginsGLPI/addressing#132 ·
-
5.14.0 PIE packages still declare PHP >=8.3, so PIE installs them on PHP 8.3 and the build failsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100