문서 메뉴
문서 홈
/ /
Atlas Device SDK
/ /

managed 이메일/비밀번호 사용자 - Swift SDK

이 페이지의 내용

  • 새 사용자 계정 등록
  • 신규 사용자의 이메일 주소 확인
  • 사용자 확인 방법 재시도
  • 사용자 확인 이메일 재전송
  • 사용자 확인 함수 재시도
  • 사용자 비밀번호 재설정
  • 비밀번호 재설정 이메일 보내기
  • 비밀번호 재설정 함수 실행
  • 완료 핸들러를 사용한 이메일/비밀번호 사용자 메서드

Atlas App Services 앱에서 이메일/비밀번호 제공자 를 활성화하면 클라이언트 코드에서 새 계정을 등록하고, 이메일 주소를 확인하고, 사용자 비밀번호를 재설정할 수 있습니다.

버전 10.16.0에서 변경됨: 이메일/비밀번호 사용자 API에 비동기/대기 지원이 추가되었습니다. 이 페이지의 코드 예제는 비동기/대기 구문으로 업데이트되었습니다. 이전 구문의 예는 완료 핸들러를 사용한 이메일/비밀번호 사용자 예제를 참조하세요.

RLMApp *app = [RLMApp appWithId:YOUR_APP_ID];
RLMEmailPasswordAuth *client = [app emailPasswordAuth];
NSString *email = @"skroob2@example.com";
NSString *password = @"password12345";
[client registerUserWithEmail:email password:password completion:^(NSError *error) {
if (error != nil) {
NSLog(@"Failed to register: %@", [error localizedDescription]);
return;
}
// Registering just registers. You can now log in.
NSLog(@"Successfully registered user.");
}];
let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "skroob@example.com"
let password = "password12345"
do {
try await client.registerUser(email: email, password: password)
// Registering just registers. You can now log in.
print("Successfully registered user.")
} catch {
print("Failed to register: \(error.localizedDescription)")
}
RLMApp *app = [RLMApp appWithId:YOUR_APP_ID];
RLMEmailPasswordAuth *client = [app emailPasswordAuth];
// Token and tokenId are query parameters in the confirmation
// link sent in the confirmation email.
NSString *token = @"someToken";
NSString *tokenId = @"someTokenId";
[client confirmUser:token tokenId:tokenId completion:^(NSError *error) {
if (error != nil) {
NSLog(@"User confirmation failed: %@", [error localizedDescription]);
return;
}
// User confirmed
NSLog(@"Successfully confirmed user.");
}];
let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
// Token and tokenId are query parameters in the confirmation
// link sent in the confirmation email.
let token = "someToken"
let tokenId = "someTokenId"
do {
try await client.confirmUser(token, tokenId: tokenId)
// User email address confirmed.
print("Successfully confirmed user.")
} catch {
print("User confirmation failed: \(error.localizedDescription)")
}

SDK는 사용자 확인 이메일을 재전송하거나 사용자 지정 확인 방법을 재시도할 수 있는 방법을 제공합니다.

확인 이메일 을 다시 보냅니다. 각 URL의 확인 토큰은 30 분 후에 만료됩니다. 사용자가 해당 기간 내에 링크를 따라 확인 및 확인을 하지 않을 경우, 새 확인 이메일을 요청해야 합니다.

let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "skroob@example.com"
// If Realm is set to send a confirmation email, we can
// send the confirmation email again here.
do {
try await client.resendConfirmationEmail(email)
// The confirmation email has been sent
// to the user again.
print("Confirmation email resent")
} catch {
print("Failed to resend confirmation email: \(error.localizedDescription)")
}

버전 10.9.0의 새로운 기능.

사용자 지정 사용자 확인 함수를 다시 시도합니다.

let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "skroob@example.com"
// If Realm is set to run a custom confirmation function,
// we can trigger that function to run again here.
do {
try await client.retryCustomConfirmation(email)
// The custom confirmation function has been
// triggered to run again for the user.
print("Custom confirmation retriggered")
} catch {
print("Failed to retry custom confirmation: \(error.localizedDescription)")
}

사용자 비밀번호 재설정은 여러 단계를 거쳐야 합니다.

  1. 클라이언트 앱에서는 사용자가 비밀번호를 재설정할 수 있는 UI를 제공합니다. 그런 다음 App Services App은 이메일을 보내거나 사용자의 신원을 확인하는 사용자 지정 함수를 실행할 수 있습니다.

  2. 사용자 신원을 확인한 후 비밀번호 재설정 요청을 완료할 수 있습니다.

  3. 비밀번호 재설정이 완료된 후, 사용자는 새로운 비밀번호를 사용하여 로그인할 수 있습니다.

선호하는 비밀번호 재설정 방법을 설정하는 방법에 대한 자세한 내용은 Atlas App Services 이메일/비밀번호 인증 문서를 참조하세요.

사용자의 신원을 확인하기 위해 비밀번호 재설정 이메일을 보내려면 비밀번호 재설정 이메일을 보내도록 앱을 구성해야 합니다.

비밀번호 재설정 프로세스를 시작하려면 사용자의 이메일로 sendResetPasswordEmail 을(를) 호출합니다. App Services에서 고유 URL이 포함된 이메일을 사용자에게 보냅니다. 사용자는 30분 이내에 이 URL을 방문하여 재설정을 확인해야 합니다.

사용자가 비밀번호 재설정 이메일을 통해 URL을 방문한 후 사용자의 이메일, 새 비밀번호, 고유 URL에 제공된 tokentokenId 를 사용하여 resetPassword 을(를) 호출합니다.

사용자가 30분 이내에 비밀번호 재설정 이메일에 포함된 URL을 방문하지 않으면 tokentokenId 이(가) 만료됩니다. 비밀번호 재설정 프로세스를 다시 시작해야 합니다.

RLMApp *app = [RLMApp appWithId:YOUR_APP_ID];
RLMEmailPasswordAuth *client = [app emailPasswordAuth];
// If Realm app password reset mode is "Send a password reset email",
// we can do so here:
NSString *email = @"forgot.my.password@example.com";
[client sendResetPasswordEmail:email completion:^(NSError *error) {
if (error != nil) {
NSLog(@"Failed to send reset password email: %@", [error localizedDescription]);
return;
}
// Email sent.
NSLog(@"Successfully sent reset password email.");
}];
// Later...
NSString *newPassword = @"mynewpassword12345";
// Token and tokenId are query parameters in the confirmation
// link sent in the reset password email.
NSString *token = @"someToken";
NSString *tokenId = @"someTokenId";
[client resetPasswordTo:newPassword token:token tokenId:tokenId completion:^(NSError *error) {
if (error != nil) {
NSLog(@"Failed to reset password: %@", [error localizedDescription]);
return;
}
// Password reset.
NSLog(@"Successfully reset password.");
}];
let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "forgot.my.password@example.com"
// If Realm app password reset mode is "Send a password reset email",
// we can do so here:
do {
try await client.sendResetPasswordEmail(email)
print("Password reset email sent.")
} catch {
print("Reset password email not sent: \(error.localizedDescription)")
}
// Later...
let newPassword = "mynewpassword12345"
// Token and tokenId are query parameters in the reset password
// link sent in the reset password email.
let token = "someToken"
let tokenId = "someTokenId"
do {
try await client.resetPassword(to: newPassword, token: token, tokenId: tokenId)
print("Password reset successful.")
} catch {
print("Failed to reset password: \(error.localizedDescription)")
}

비밀번호 재설정 함수를 실행 하도록 앱을 구성할 때는 SDK 에서 를 호출할 때 실행되어야 하는 함수를 정의합니다. 이 함수는 사용자 이름, 비밀번호 및 여러 개의 추가 인수를 사용할 수 있습니다. 이러한 인수를 사용하여 사용자가 비밀번호 재설정을 성공적으로 완료하기 위해 전달해야 하는 보안 질문 답변 또는 기타 과제와 같은 세부 정보를 지정할 수 있습니다.

비밀번호 재설정 흐름을 직접 정의하려는 경우 사용자 지정 비밀번호 재설정 함수를 사용하는 것이 더 나을 수 있습니다. 예를 들어 특정 도메인에서 사용자 지정 비밀번호 재설정 이메일을 보낼 수 있습니다. 또는 이메일 이외의 서비스를 사용하여 사용자의 신원을 확인할 수 있습니다.

App Services 측에서 이 메서드를 호출할 때 실행되는 사용자 지정 비밀번호 재설정 함수를 정의합니다. 이 함수는 세 가지 가능한 상태 중 하나를 반환할 수 있습니다.

  • fail

  • pending

  • success

SDK에서는 fail 상태를 오류로 처리합니다. SDK callResetPasswordFunction() 는 반환 값을 받지 않으므로 pending 또는 success 상태를 클라이언트에 반환하지 않습니다.

사용자가 신원을 확인하기 위해 몇 가지 추가 단계를 수행하도록 하려는 경우 Atlas App Services 비밀번호 재설정 함수pending 을 반환할 수 있습니다. 그러나 해당 반환 값은 SDK의 callResetPasswordFunction() 로 전달되지 않으므로 클라이언트 앱은 pending 상태를 처리하는 자체 로직을 구현해야 합니다.

서버 측 함수가 사용자 지정 이메일 제공자를 사용하여 이메일을 보낼 수 있습니다. 또는 SMS를 사용하여 문자 메시지로 사용자의 신원을 확인할 수 있습니다.

Atlas App Services 비밀번호 재설정 함수 컨텍스트에서 tokentokenId 에 액세스할 수 있습니다. Atlas App Services 비밀번호 재설정 함수에서 이 정보를 전달하는 경우 범용 링크 를 사용하여 이러한 값을 앱에 다시 전달할 수 있습니다. . 그런 다음 클라이언트 애플리케이션은 resetPassword 를 호출하여 비밀번호 재설정 흐름을 완료할 수 있습니다.

let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "forgot.my.password@example.com"
let newPassword = "mynewpassword12345"
// The password reset function takes any number of
// arguments.
let args: [AnyBSON] = []
// This SDK call maps to the custom password reset
// function that you define in the backend. In this example,
// we assume your function waits for additional identity
// confirmation. Calling this function only kicks
// off the password reset function. It does not reset the password.
do {
try await client.callResetPasswordFunction(email: email, password: newPassword, args: args)
print("Successfully called the password reset function")
} catch {
print("Password reset failed: \(error.localizedDescription)")
}
// Later...
// Token and tokenId are parameters you can access
// in the App Services function context. You could send
// this to the user via email, SMS, or some other method.
let token = "someToken"
let tokenId = "someTokenId"
do {
try await client.resetPassword(to: newPassword, token: token, tokenId: tokenId)
print("Password reset successful.")
} catch {
print("Failed to reset password: \(error.localizedDescription)")
}

Atlas App Services 비밀번호 재설정 함수 가 함수 내에서 추가 유효성 검사를 수행하거나 비밀번호 재설정을 시도하기 전에 사용자 ID의 유효성을 검사한 경우, success 을 반환하도록 Atlas App Services 함수를 구성할 수 있습니다. 그러나 해당 반환 값은 SDK의 callResetPasswordFunction() 로 전달되지 않으므로 클라이언트 앱은 success 상태를 처리하는 자체 로직을 구현해야 합니다.

이 예제의 함수를 호출하면 전체 비밀번호 재설정 프로세스가 수행됩니다.

let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "forgot.my.password@example.com"
let newPassword = "mynewpassword12345"
// The password reset function takes any number of
// arguments. You might ask the user to provide answers to
// security questions, for example, to verify the user
// should be able to complete the password reset.
let args: [AnyBSON] = []
// This SDK call maps to the custom password reset
// function that you define in the backend
do {
try await client.callResetPasswordFunction(email: email, password: newPassword, args: args)
print("Password reset successful!")
} catch {
print("Password reset failed: \(error.localizedDescription)")
}

Apple의 비동기/대기 구문 을 사용하지 않는 경우 , 이러한 모든 메서드는 완료 핸들러에서 사용할 수 있습니다. 이 예제에서는 완료 핸들러 구문을 사용하여 사용자를 등록하는 방법 을 보여 줍니다.

let app = App(id: YOUR_APP_SERVICES_APP_ID)
let client = app.emailPasswordAuth
let email = "skroob@example.com"
let password = "password12345"
client.registerUser(email: email, password: password) { (error) in
guard error == nil else {
print("Failed to register: \(error!.localizedDescription)")
return
}
// Registering just registers. You can now log in.
print("Successfully registered user.")
}

돌아가기

사용자 메타데이터

다음

다중 사용자 애플리케이션