MeWrite Docs

SSO: Single Sign-On Failure

シングルサインオン(SSO)の認証プロセスが失敗するエラー

概要

SSO Login Failed は、シングルサインオン(SSO)の認証プロセスにおいて、Identity Provider(IdP)とService Provider(SP)間の通信や設定に問題がある場合に発生するエラーです。SAML、OpenID Connect、OAuthなど複数のプロトコルで共通して見られます。

エラーメッセージ

SSO Login Failed: Redirect URI mismatch
Error: The SSO configuration is invalid. Contact your administrator.
AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application.
Error 400: redirect_uri_mismatch - The redirect_uri does not match the authorized redirect URIs.
SSO Error: User not assigned to this application

原因

  1. リダイレクトURLの不一致: IdPに登録されたリダイレクトURLとSPからの要求が異なる
  2. IdP側の設定不備: アプリケーション設定が不正または未完了
  3. SP側の設定不備: Client ID/Secret、メタデータURLが間違っている
  4. ユーザー未割り当て: IdP側でユーザーがアプリケーションに割り当てられていない
  5. 証明書の期限切れ: SAML署名証明書が期限切れ
  6. プロトコルバージョンの不一致: SAML 1.1 vs 2.0、OAuth 2.0 vs OIDC

解決策

1. リダイレクトURLの確認と修正

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Google Cloud Console の場合
# 1. APIs & Services > Credentials
# 2. OAuth 2.0 Client IDs から対象のクライアントを選択
# 3. Authorized redirect URIs を確認

# 正しいリダイレクトURI の例
https://app.example.com/auth/callback
https://app.example.com/auth/google/callback

# よくある間違い
http://app.example.com/auth/callback    # http vs https
https://app.example.com/auth/callback/  # 末尾のスラッシュ
https://www.app.example.com/auth/callback  # www の有無

2. Azure AD(Microsoft Entra ID)の設定

1
2
3
4
5
6
# Azure AD でのアプリケーション設定確認
az ad app show --id $APP_CLIENT_ID --query '{
  displayName: displayName,
  replyUrls: replyUrlsWithType[].url,
  identifierUris: identifierUris
}'
1
2
3
4
5
6
7
8
9
// MSAL.js の設定例
const msalConfig = {
  auth: {
    clientId: process.env.AZURE_CLIENT_ID,
    authority: `https://login.microsoftonline.com/${process.env.AZURE_TENANT_ID}`,
    redirectUri: 'https://app.example.com/auth/callback', // IdP側と完全一致が必要
    postLogoutRedirectUri: 'https://app.example.com'
  }
};

3. Okta の設定確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// Okta OIDC 設定例
const OktaJwtVerifier = require('@okta/jwt-verifier');

const oktaJwtVerifier = new OktaJwtVerifier({
  issuer: 'https://your-org.okta.com/oauth2/default',
  clientId: process.env.OKTA_CLIENT_ID
});

// トークン検証
async function verifyToken(accessToken) {
  try {
    const jwt = await oktaJwtVerifier.verifyAccessToken(accessToken, 'api://default');
    return jwt.claims;
  } catch (err) {
    console.error('Token verification failed:', err.message);
    throw err;
  }
}

4. Google Workspace SSO の設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Flask + Google OIDC
from authlib.integrations.flask_client import OAuth

oauth = OAuth(app)
google = oauth.register(
    name='google',
    client_id=os.environ['GOOGLE_CLIENT_ID'],
    client_secret=os.environ['GOOGLE_CLIENT_SECRET'],
    server_metadata_url='https://accounts.google.com/.well-known/openid-configuration',
    client_kwargs={
        'scope': 'openid email profile',
        'prompt': 'select_account'  # アカウント選択画面を表示
    }
)

@app.route('/login')
def login():
    redirect_uri = url_for('callback', _external=True)
    # redirect_uri が IdP 側の設定と一致しているか確認
    app.logger.info(f'Redirect URI: {redirect_uri}')
    return google.authorize_redirect(redirect_uri)

@app.route('/auth/callback')
def callback():
    try:
        token = google.authorize_access_token()
        user_info = token.get('userinfo')
        return create_session(user_info)
    except Exception as e:
        app.logger.error(f'SSO callback error: {e}')
        return redirect('/login?error=sso_failed')

5. デバッグ手順

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 1. IdP のメタデータを確認
curl -s https://accounts.google.com/.well-known/openid-configuration | jq .

# 2. Azure AD のメタデータ
curl -s "https://login.microsoftonline.com/${TENANT_ID}/v2.0/.well-known/openid-configuration" | jq .

# 3. 認証リクエストのURLを確認(ブラウザの開発者ツール)
# Network タブで認証リクエストのURLパラメータを確認:
# - client_id が正しいか
# - redirect_uri が正しいか
# - scope が正しいか
# - response_type が正しいか

# 4. エラーレスポンスのパラメータを確認
# コールバックURLのクエリパラメータに error, error_description が含まれる
# 例: https://app.example.com/callback?error=redirect_uri_mismatch&error_description=...

6. チェックリスト

1
2
3
4
5
6
7
8
9
SSO 設定チェックリスト:
[ ] Client ID / Client Secret が正しいか
[ ] Redirect URI が IdP 側とSP側で完全一致しているか
[ ] スコープ(scope)が適切か
[ ] ユーザーがアプリケーションに割り当てられているか
[ ] 証明書が有効期限内か(SAML の場合)
[ ] サーバー時刻が同期されているか
[ ] HTTPS が使用されているか(本番環境)
[ ] ログアウトURLが設定されているか

関連エラー

Security の他のエラー

最終更新: 2026-02-03