Docs Menu

Okta JWT Authentication (Custom JWT)

You can configure the Custom JWT authentication provider to authenticate users that you manage with Okta.

You will need the following to use Okta:

  • An Okta project. To learn more, refer to the Okta documentation.

  • 아직 사용자 지정 JWT 인증을 사용하지 않는 App Services App입니다. 새 App Services App을 만드는 방법을 알아보려면 앱 생성을 참조하세요.

  • If you're using the command line interface, you need 앱 서비스 CLI to be installed and authenticated on your local system.

  • Admin API를 사용하는 경우 MongoDB Atlas Admin API 공개/비공개 키 쌍이 필요합니다. API 키에는 프로젝트 소유자 권한이 있어야 합니다.

Create an application in Okta that represents your client application. The type of application you create depends on your use case. For example, if you're building a web browser app, you might create a Single-Page Application (SPA) or Web application in Okta.

Once you've configured the application, create an authorization server in Okta that represents your App Services App. You can use any name and description. Set the server Audience to your App Services App's Client App ID. For example, myapp-abcde.

To learn more about how to set up an Okta application and authorization server, refer to Create an authorization server in the Okta documentation.

UI에서 사용자 지정 JWT 인증을 구성하거나 CLI 또는 관리 API를 사용하여 기본 구성 파일을 직접 수정하여 구성할 수 있습니다. 아래에서 선호하는 방법을 선택하세요.

왼쪽 탐색 메뉴에서 Authentication을 클릭합니다. 그런 다음 Authentication Providers 탭을 클릭하고 Custom JWT 제공자를 선택합니다.

Now you can configure the Custom JWT authentication provider to work with your Okta project.

  1. 토글을 클릭하여 제공자를 활성화합니다.

  2. 세트 Verification Method to Use a JWK URI. Specify your Okta Authorization Server's JWK URI in the JWK URI field.

    Your Okta JWK URI should resemble the following:

    https://<Your Okta Domain>/oauth2/<Your Authorization Server ID>/v1/keys

    참고

    You can get your exact JWK URI from the Okta UI by following the Metadata URI link for your Authorization server. Use the value listed in the jwks_uri field.

  3. Define Metadata Fields to map data from the Okta JWT to the corresponding App Services user account.

    You do not have to map metadata fields from the Okta JWT. However, you might find them useful for getting user information from Okta into your App. To learn more about metadata fields and how to configure them, see Custom JWT metadata fields .

  4. Leave the value of Audience blank.

  5. 변경 사항을 배포하려면 Save 를 클릭합니다.

다음 명령을 실행하여 --remote 값을 앱의 클라이언트 앱 ID로 바꿉니다. 이렇게 하면 앱의 최신 구성 파일의 로컬 사본이 다운로드되고 앱과 동일한 이름을 사용하는 구성 파일 디렉토리로 이동합니다.

appservices pull --remote "myapp-abcde"
cd myapp

Add a new Custom JWT authentication provider to your App's /auth/providers.json file. Use the following configuration as a template. Make sure to:

  • Replace the jwkURI value with your Okta Authorization Server's JWK URI.

  • Define Custom JWT metadata fields to map data from the Okta JWT. This is optional, however, you might find the field mapping useful for getting user information from Okta into your App.

/auth/providers.json
{
"custom-token": {
"name": "custom-token",
"type": "custom-token",
"disabled": false,
"config": {
"audience": [],
"jwkURI": "https://<Your Okta Domain>/oauth2/<Your Authorization Server ID>/v1/keys",
"useJWKURI": true
},
"secret_config": {
"signingKeys": []
},
"metadata_fields": []
}
}

변경 사항을 /auth/providers.json 에 저장합니다. 그런 다음 업데이트된 구성 파일을 푸시하여 앱을 배포합니다.

appservices push

인증 제공자 생성 엔드포인트를 사용하여 앱에 새 사용자 지정 JWT 인증 공급자를 추가합니다.

다음 구성을 템플릿으로 사용합니다. 다음을 확인하세요.

  • 앱의 $PROJECT_ID$APP_ID지정

  • Authorization 헤더에 관리자 API 액세스 토큰을 포함합니다.

  • Replace the jwkURI value in the request body with your Okta Authorization Server's JWK URI.

  • Define Custom JWT metadata fields to map data from the Okta JWT. This is optional, however, you might find the field mapping useful for getting user information from Okta into your App.

curl "https://services.cloud.mongodb.com/api/admin/v3.0/groups/$PROJECT_ID/apps/$APP_ID/auth_providers" \
-X "POST" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "custom-token",
"type": "custom-token",
"disabled": false,
"config": {
"audience": [],
"jwkURI": "https://<Your Okta Domain>/oauth2/<Your Authorization Server ID>/v1/keys",
"useJWKURI": true
},
"secret_config": {
"signingKeys": []
},
"metadata_fields": []
}'

Once you've configured the Custom JWT authentication provider to use Okta, you can log in to your App Services App with an Okta JWT access token.

  1. Log the user into Okta. To learn how, see the relevant Okta SDK documentation for your platform and programming language.

  2. Get the user's Okta access token from the login response.

  3. Use the Okta access token to authenticate with Atlas App Services. You can start a session over HTTP or log in with an SDK. To learn how, see the docs for your SDK: