Java/오류노트
[Java/오류노트] Solved - Keycloak : openid-connect/userinfo 403 Forbidden 해결방법
adjh54
2025. 2. 4. 20:03
728x170
Keycloak에서 openid-connect/userinfo 엔드포인트로 호출할 때, 발생하는 403 Forbidden 에러에 대해 알아봅니다.
1) 문제점
💡 문제점
- openid-connect/userinfo 엔드포인트로 Header 내에 “Authorization” 값으로 유효한 접근 토큰(Access Token)을 전달하였으나 아래와 같은 403 에러가 발생하였습니다.
package com.adjh.springbootkeycloaksub.service;
import com.adjh.springbootkeycloaksub.dto.TokenIntrospectionReqDto;
import com.adjh.springbootkeycloaksub.dto.TokenIntrospectionResDto;
import lombok.Getter;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
/**
* Please explain the class!!
*
* @author : leejonghoon
* @fileName : KeycloakService
* @since : 2025. 2. 3.
*/
@FeignClient(
name = "keycloak-auth-service",
url = "<http://localhost:9001/realms/dev-realm/protocol/openid-connect>"
)
@Service
public interface KeycloakService {
/**
* 사용자 리스트를 조회합니다.
*
* @param bearerToken
* @return
*/
@GetMapping(value = "/userinfo")
Object getUserInfo(@RequestHeader("Authorization") String bearerToken);
}

💡[참고] keycloak openid-connect/userinfo 엔드포인트 API Document
Final: OpenID Connect Core 1.0 incorporating errata set 2
OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It enables Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about
openid.net
2) 해결방법
💡 해결방법
- Keycloak Client Scope에서 scope 중 openid를 추가하면 됩니다.
1. Realm > Client scopes > Create client scope를 선택합니다.

2. Create client scope
💡 Create client scope
- Name : openid
- Type : Default
- Include in token scope : ON
- Save

3. Clients > Client 선택

4. Client scopes > Add client scope 선택

5. openid 선택 > Default 선택

6. 추가 확인

3) 결과 확인
💡 결과 확인
- 아래와 같이 정상적으로 수행됨을 확인하였습니다.

오늘도 감사합니다 😀

그리드형