Apple ID 인증
이 페이지의 내용
개요
Apple ID 인증 제공자를 통해 사용자는 Apple로 로그인을 통해 Apple ID 자격 증명으로 로그인할 수 있습니다. 이 인증 방법은 업계 표준 OAuth 2.0 권한 부여 프로토콜을 사용합니다.
사용자가 Sign in with Apple(Apple로 로그인)을 통해 성공적으로 로그인하면 Apple은 이 포함된 자격 증명 객체 JSON web token 를 ID 반환합니다. Apple 제공자 가 사용자를 인증하는 데 사용하는 사용자가 앱 에 권한을 부여한 경우 자격 증명 객체 에 사용자 이름과 이메일 주소 도 포함될 수 있습니다.
Sign in with Apple(Apple로 로그인) 구현 방법에 대한 자세한 내용은 다음 섹션을 참조하세요.
공식 Apple로 로그인 문서 Apple 개발자 포털에서
WWDC 2019의 Apple로 로그인 소개 세션
관련 참고 애플리케이션.
참고
Apple ID 인증을 사용하는 iOS 앱은 iOS 13 이상을 대상으로 해야 합니다.
다음 다이어그램은 OAuth 로직의 흐름을 보여줍니다.
준비물
Apple ID 인증을 구현하려면 먼저 다음 사항이 필요합니다.
Xcode 11 또는 최신 버전입니다.
Apple ID 인증 구성
Atlas App Services와 함께 Sign-in with Apple(Apple로 로그인)을 사용할 경우, 모바일 애플리케이션 또는 웹 애플리케이션 중 하나에 대해 Apple 인증 제공자를 구성할 수 있습니다.
양쪽에 Sign in with Apple(Apple로 로그인)을 사용하려면 웹 또는 모바일 앱 중 하나에 대한 수동 Sign in with Apple(Apple로 로그인) 흐름을 직접 설정하면 됩니다. 그런 다음 Custom JWT authentication provider(사용자 지정 JWT 인증 제공자)와 함께 반환되는 JWT를 사용하세요. 이후 Realm SDK에서 각 인증 제공자의 사용자 ID를 단일 사용자에 연결할 수 있습니다.
웹 또는 모바일 애플리케이션에서만 Apple로 로그인을 사용하려면 애플리케이션 유형을 선택하고 이 가이드를 따르세요.
앱에 Apple로 로그인 추가
이 기능을 사용하려면 앱에 Apple로 로그인 권한이 있어야 합니다.
Xcode에서 앱 대상을 선택합니다.
Go to the Signing & Capabilities tab, and select + Capability.
Apple로 로그인 기능을 검색하여 선택합니다.
그런 다음 Apple 개발자 포털에서 허용 여부를 확인합니다.
Navigate to the Certificates, Identifiers and Profiles page of the Apple Developer Portal.
Select the identifier for your app from the dropdown. This takes you to your App ID Configuration pane.
Scroll down until you see the checkbox for Sign In with Apple. If that checkbox is not selected, select it. If you've made changes, press the Save button.
Note the Bundle ID of your app. You need the Bundle ID when you create a client secret and when you configure Sign in with Apple in App Services.
비공개 키 만들기
Apple로 로그인을 위한 클라이언트 비밀 번호는 사용자가 생성하고 비공개 키로 서명하는 JSON Web Token입니다. Apple 개발자 포털을 통해 비공개 키를 생성해야 합니다.
왼쪽 탐색 패널에서 Keys 을 클릭합니다.
Click the blue plus icon next to Keys.
On the Register a New Key page, enter a descriptive Key Name and then scroll down to find the Sign in with Apple row. Check the checkbox to enable Sign in with Apple and then click Configure.
On the Configure Key page, select the App ID for your app as the Primary App ID and then click Save.
Click Continue to review your key configuration. When you're sure that you've configured the key correctly, click Register.
Copy the Key ID value somewhere that you can access it later and then click Download to download the key as a
.p8
text file. You will use these to generate the client secret.중요
키 저장
키는 한 번만 다운로드할 수 있습니다. 다시 필요할 경우를 대비하여 키를 안전한 곳에 저장해야 합니다. 키를 분실한 경우 새 키를 생성해야 합니다.
클라이언트 비밀 JWT 만들기
이제 Apple ID 인증 제공자에 대한 클라이언트 비밀 JWT를 만들 수 있습니다. 다음 정보가 있는지 확인하십시오.
The Bundle ID of your app. You'll use this as the
client_id
in the script below.The Key ID of the key that you created and the
.p8
file that contains the key.Apple 팀 ID. Apple 개발자 포털의 오른쪽 상단에서 찾을 수 있습니다.
필요한 정보가 모두 있음을 확인한 후에는 스크립트를 사용하여 JWT를 생성할 수 있습니다. 직접 스크립트를 정의하거나 이 단계의 스크립트를 사용할 수 있습니다.
JSON web token을 JSON web token 생성하기 위해 사용합니다.JSON web tokengem. 설치하려면 다음을 실행 합니다.
gem install jwt
generate_client_secret.rb
이라는 새 파일을 만들고 다음의 코드 블록을 파일에 복사합니다.
# Source: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple require 'jwt' # Update these values with your app's information team_id = '<Apple Team ID>' client_id = '<Bundle ID or Services ID>' key_id = '<Apple Key ID>' key_file = '<Key File Path>' # Define the JWT's headers and claims headers = { # The token must be signed with your key 'kid' => key_id } claims = { # The token is issued by your Apple team 'iss' => team_id, # The token applies to Apple ID authentication 'aud' => 'https://appleid.apple.com', # The token is scoped to your application 'sub' => client_id, # The token is valid immediately 'iat' => Time.now.to_i, # The token expires in 6 months (maximum allowed) 'exp' => Time.now.to_i + 86400*180, } # Read in the key and generate the JWT ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file token = JWT.encode claims, ecdsa_key, 'ES256', headers # Print the JWT to stdout puts token
team_id
, client_id
, key_id
, key_file
값을 애플리케이션 정보와 일치하도록 업데이트한 다음 파일을 저장합니다. JWT를 생성할 준비가 되면 셸에서 스크립트를 실행합니다.
ruby generate_client_secret.rb >> client_secret.txt
중요
JWT 저장
generate_client_secret.rb
스크립트는 stdout으로 출력됩니다. 이 함수를 호출하면 client_secret.txt
이라는 파일에 stdout이 추가됩니다. App Services에서 Apple ID 제공자를 구성하려면 JWT가 필요합니다.
App Services에서 제공자 구성하기
이 지점에서 Apple 애플리케이션을 구성하고 필요한 OAuth 2.0 자격 증명을 생성했습니다. 이제 App Services 클라이언트 애플리케이션 사용자가 로그인할 수 있도록 자격 증명을 사용하여 Apple ID 인증 제공자를 구성할 수 있습니다.
Click Authentication in the left navigation menu and then click Apple ID.
Turn on the Provider Enabled toggle.
For the App Services Client ID, enter your application's Bundle ID.
For Client Secret, create a new secret with a descriptive name and set the Client Secret Value to the JWT string that you generated. Alternatively, you can select a pre-existing secret that contains the JWT.
Click Save to finish configuring the provider. To make the provider available to client applications, you need to deploy your changes. Click Review & Deploy Changes and then click Deploy.
appservices로 Apple 인증 제공자 를 활성화 하고 구성하려면 /auth/providers.json
에서 구성 객체 를 정의합니다.
Apple 제공자 구성의 형식은 다음과 같습니다.
{ "oauth2-apple": { "name": "oauth2-apple", "type": "oauth2-apple", "disabled": <boolean>, "config": { "clientId": "<Bundle ID>" }, "secret_config": { "clientSecret": "<Secret Name>" }, "redirect_uris": ["<string>", ...] } }
필드 | 설명 |
---|---|
Client ID config.clientId | Required. Your application's Bundle ID. |
Client Secret secret_config.clientSecret | Required. The name of a 비밀 that stores the Client Secret JWT that you generated. |
Redirect URIs redirect_uris | 웹 애플리케이션에 필요합니다. 모바일 애플리케이션에는 필요하지 않습니다. |
구성 파일 을 생성한 후에는 애플리케이션을 배포하여 클라이언트 애플리케이션 에서 Apple ID 인증 제공자 를 사용할 수 있도록 설정할 수 있습니다.
App Services CLI 를 사용하여 초안 애플리케이션 을 배포 하려면 다음을 수행합니다.
appservices push
자동 Github 배포서버를 사용하여 초안 애플리케이션 을 배포 하려면 다음을 수행합니다.
git add ./auth/providers.json git commit -m "Configure and Enable Apple ID Authentication" git push origin <branch name>
앱 ID 만들기
Apple 앱 ID 는 애플리케이션 을 나타내며 이를 통해 Apple로 로그인과 같은 서비스에 액세스 할 수 있습니다. Apple ID 제공자 를 구성하려면 새 앱 ID 를 만들어야 합니다.
Navigate to the Certificates, Identifiers and Profiles page of the Apple Developer Portal.
왼쪽 탐색 패널에서 Identifiers 을 클릭합니다.
Click the blue plus icon next to Identifiers.
On the Register a New Identifier page, select App IDs and then click Continue.
On the Register an App ID page, select the Platform that your app runs on and then enter a brief Description and a reverse-dns notation Bundle ID.
Scroll down the Register an App ID page until you see the Sign in with Apple capability. Check the checkbox to enable the capability.
Press the Continue button at the top of the page. Complete any other setup steps that apply to your app, and then press the Register button.
서비스 ID 만들기
Apple 서비스 ID 는 단일 애플리케이션 을 나타내며, 이를 통해 권한 부여 콜백 URL 을 구성하고 애플리케이션 의 비공개 키를 정의할 수 있습니다.
왼쪽 탐색 패널에서 Identifiers 을 클릭합니다.
Click the blue plus icon next to Identifiers.
On the Register a New Identifier page, select Services IDs and then click Continue.
On the Register a Services ID page, enter a brief Description and a reverse-dns notation Identifier.
중요
식별자 저장
The Identifier value of the Services ID is your application's Client ID. You will need this value later to configure the Apple ID provider in Atlas App Services.
Press the Continue button. Confirm the details, and then press Register.
Click into the service you just created. Check the checkbox to enable Sign in with Apple and then click Configure. Select the App ID that you created as the Primary App ID.
Enter your domains, subdomains, and return URLs for the Services ID. Press the Next button.
Click Continue and then click Save. Confirm that you have correctly configured the Services ID and then click Register.
비공개 키 만들기
Apple로 로그인을 위한 클라이언트 비밀 번호는 사용자가 생성하고 비공개 키로 서명하는 JSON Web Token입니다. Apple 개발자 포털을 통해 비공개 키를 생성해야 합니다.
왼쪽 탐색 패널에서 Keys 을 클릭합니다.
Click the blue plus icon next to Keys.
On the Register a New Key page, enter a descriptive Key Name and then scroll down to find the Sign in with Apple row. Check the checkbox to enable Sign in with Apple and then click Configure.
On the Configure Key page, select the App ID that you created as the Primary App ID and then click Save.
Click Continue to review your key configuration. When you're sure that you've configured the key correctly, click Register.
Copy the Key ID value somewhere that you can access it later and then click Download to download the key as a
.p8
text file. You will use these to generate the client secret.중요
키 저장
키는 한 번만 다운로드할 수 있습니다. 다시 필요할 경우를 대비하여 키를 안전한 곳에 저장해야 합니다. 키를 분실한 경우 새 키를 생성해야 합니다.
클라이언트 비밀 JWT 만들기
이제 Apple ID 인증 제공자에 대한 클라이언트 비밀 JWT를 만들 수 있습니다. 다음 정보가 있는지 확인하십시오.
The Services ID that you created. You'll use this as the
client_id
in the script below.- The Key ID of the key that you created and the
.p8
- 키가 포함된 파일 입니다.
- The Key ID of the key that you created and the
- Apple 팀 ID. Apple의 오른쪽 상단에서 찾을 수 있습니다.
- 개발자 포털.
필요한 정보가 모두 있음을 확인한 후에는 스크립트를 사용하여 JWT를 생성할 수 있습니다. 직접 스크립트를 정의하거나 이 단계의 스크립트를 사용할 수 있습니다.
JSON web token을 JSON web token 생성하기 위해 사용합니다.JSON web tokengem. 설치하려면 다음을 실행 합니다.
gem install jwt
generate_client_secret.rb
이라는 새 파일을 만들고 다음의 코드 블록을 파일에 복사합니다.
# Source: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple require 'jwt' # Update these values with your app's information team_id = '<Apple Team ID>' client_id = '<Bundle ID or Services ID>' key_id = '<Apple Key ID>' key_file = '<Key File Path>' # Define the JWT's headers and claims headers = { # The token must be signed with your key 'kid' => key_id } claims = { # The token is issued by your Apple team 'iss' => team_id, # The token applies to Apple ID authentication 'aud' => 'https://appleid.apple.com', # The token is scoped to your application 'sub' => client_id, # The token is valid immediately 'iat' => Time.now.to_i, # The token expires in 6 months (maximum allowed) 'exp' => Time.now.to_i + 86400*180, } # Read in the key and generate the JWT ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file token = JWT.encode claims, ecdsa_key, 'ES256', headers # Print the JWT to stdout puts token
team_id
, client_id
, key_id
, key_file
값을 애플리케이션 정보와 일치하도록 업데이트한 다음 파일을 저장합니다. JWT를 생성할 준비가 되면 셸에서 스크립트를 실행합니다.
ruby generate_client_secret.rb >> client_secret.txt
중요
JWT 저장
generate_client_secret.rb
스크립트는 stdout으로 출력됩니다. 이 함수를 호출하면 client_secret.txt
이라는 파일에 stdout이 추가됩니다. App Services에서 Apple ID 제공자를 구성하려면 JWT가 필요합니다.
App Services에서 제공자 구성하기
이 지점에서 Apple 애플리케이션을 구성하고 필요한 OAuth 2.0 자격 증명을 생성했습니다. 이제 App Services 클라이언트 애플리케이션 사용자가 로그인할 수 있도록 자격 증명을 사용하여 Apple ID 인증 제공자를 구성할 수 있습니다.
Click Authentication in the left navigation menu and then click Apple ID.
Turn on the Provider Enabled toggle.
For the App Services Client ID, enter the Apple Services ID you got when you created a Services ID in step 2 above.
For Client Secret, create a new secret with a descriptive name and set the Client Secret Value to the JWT string that you generated. Alternatively, you can select a pre-existing secret that contains the JWT.
For Redirect URIs, click Add Redirect URI and enter the URL that App Services should redirect to once the OAuth process is complete. Provide a URL for a domain that you control and then use a universal link to redirect the user back to your app.
Click Save to finish configuring the provider. To make the provider available to client applications, you need to deploy your changes. Click Review & Deploy Changes and then click Deploy.
appservices
으로 Apple 인증 제공자 를 활성화 하고 구성하려면 /auth/providers.json
에서 구성 객체 를 정의합니다.
Apple 제공자 구성의 형식은 다음과 같습니다.
{ "oauth2-apple": { "name": "oauth2-apple", "type": "oauth2-apple", "disabled": <boolean>, "config": { "clientId": "<Apple Services ID>" }, "secret_config": { "clientSecret": "<Secret Name>" }, "redirect_uris": ["<string>", ...] } }
필드 | 설명 |
---|---|
Client ID config.clientId | Required. The Apple Services ID that you created when you completed step 2 above. |
Client Secret secret_config.clientSecret | Required. The name of a 비밀 that stores the Client Secret JWT that you generated. |
Redirect URIs redirect_uris | 웹 애플리케이션에 필요합니다. 허용된 리디렉션 URI 목록입니다. 사용자가 인증 프로세스 를 완료하면 App Services 는 사용자를 지정된 리디렉션 URI로 리디렉션하거나, 리디렉션 URI가 지정되지 않은 경우 인증 요청 을 시작한 URL 로 리디렉션합니다. App Services 는 프로토콜 및 모든 트레일링 슬래시를 포함하여 이 목록의 항목과 정확히 일치하는 URI로만 사용자를 리디렉션합니다. 제어하는 도메인의 URL 을 입력한 다음 범용 링크 를 사용하세요. 사용자를 앱 으로 다시 리디렉션합니다. |
구성 파일 을 생성한 후에는 애플리케이션을 배포하여 클라이언트 애플리케이션 에서 Apple ID 인증 제공자 를 사용할 수 있도록 설정할 수 있습니다.
App Services CLI 를 사용하여 초안 애플리케이션 을 배포 하려면 다음을 수행합니다.
appservices push
자동 Github 배포서버를 사용하여 초안 애플리케이션 을 배포 하려면 다음을 수행합니다.
git add ./auth/providers.json git commit -m "Configure and Enable Apple ID Authentication" git push origin <branch name>
예시
Apple 인증을 이용한 등록 및 로그인 방법에 대한 코드 예시는 Realm SDK 설명서를 참조하세요.