범위 지정된 API 키 사용

API 키를 사용하면 Discourse를 다른 시스템과 통합하거나 다양한 작업을 자동화할 수 있습니다. 그러나 강력한 기능에는 그에 상응하는 책임이 따릅니다. 악의적인 사용자가 API 키에 접근할 경우 민감한 데이터에 접근하거나 사이트에 변경 사항을 적용할 수 있습니다. 이를 완화하고 추가적인 보안 계층을 제공하기 위해 이제 스코프를 사용하여 API 키가 수행할 수 있는 작업을 제한할 수 있습니다.

스코프 및 허용된 매개변수

새 API 키를 생성할 때 원하는 스코프를 선택할 수 있습니다. :grey_question: 아이콘에 마우스를 올리면 해당 스코프의 간단한 설명을 볼 수 있습니다. :link: 버튼을 클릭하면 해당 스코프와 관련된 URL을 확인할 수 있습니다.

선택적으로 허용되는 매개변수를 지정할 수도 있습니다. 여러 값을 나열할 때는 쉼표(,)를 사용하세요.

기존 키 마이그레이션

이 기능이 추가되었을 때 기존 키는 “글로벌” 키로 전환되었습니다. 이를 스코프로 마이그레이션하려면 키를 철회하고 새로운 키를 생성해야 합니다.

사용자 정의 스코프 추가

플러그인은 add_api_key_scope 메서드를 호출하여 사용자 정의 스코프를 추가할 수 있습니다:

resource는 관련 스코프를 그룹화하는 데 사용되는 심볼이고, action은 다음 속성을 가진 해시입니다:

  • actions: 허용된 컨트롤러 작업을 포함하는 목록입니다. 형식은 controller_name#method_name입니다.
  • methods: 허용할 HTTP 메서드 목록입니다(예: %i[get]). 컨트롤러 작업 대신 HTTP 메서드로 일치시키려면 actions 대신 이 항목을 사용하세요.
  • params: 허용된 매개변수의 이름을 포함하는 목록입니다.
  • aliases: 허용된 매개변수에 대한 다른 이름을 포함하는 해시입니다.

기본 스코프가 어떻게 정의되는지 확인하려면 다음을 참조하세요:

24개의 좋아요

It seems I get 403 response for getting categories with a read only API key

curl -X GET "https://mysite/categories.json" \
-H "Api-Key: mykey" \
-H "Api-Username: system"

where I have read & read_list permissions on topics for the API key. /top.json works with the same key for instance. The endpoint works when I use a ‘Global Key’

I’d like to put the API key in my client for reading the list of categories and topics, so important to have a read only key!

Any pointers?

1개의 좋아요

Interestingly it works if no credentials are used at all!

k
i.e. curl -X GET "https://mysite/categories.json"

1개의 좋아요

Unfortunately, we only include a handful of scopes out of the box due to the high number of available endpoints. We may add new ones in the future, but in the meantime, you’ll have to extend them to suit your needs.

If you use a scoped API Key, calling endpoints not included by the scopes you choose won’t work. You can click the :link: button to see which URLs are accepted.

This only works for public sites. Also, you won’t see things like private categories unless you are logged in and have enough permissions.

6개의 좋아요

Are you taking suggestions for further scopes?

One thing I’d be interested in using our site’s API for would be for another site to check if a user exists with an email address and add to a group if so. I trust the site (another site within our parent organisation) but tightening down access options to only what’s needed seems wise if it were an option.

1개의 좋아요

I’m super happy that they have opened up an api for plugins. You can start with a plugin and see if it can be incorporated in core.

2개의 좋아요

I believe that pr-welcome for any generally useful scopes you can come up with. E.g. group_membership.edit ?

5개의 좋아요