사용자 ID 연결 - .NET SDK
이 페이지의 내용
Atlas Device SDK는 더 이상 사용되지 않습니다. 자세한 내용은 지원 중단 페이지 를 참조하세요.
Realm 은 사용자를 앱 에 로그 하기 위해 많은 인증 제공자 를 제공합니다. 각 제공자 는 고유한 사용자 ID를 생성합니다. Realm 을 사용하면 여러 자격 증명 을 하나의 사용자 ID로 병합할 수 있습니다.
예시
익명 로그인 을 제공하는 애플리케이션을 예로 들어 보겠습니다. 이를 통해 사용자는 등록하지 않고도 앱을 탐색할 수 있습니다. 사용자가 애플리케이션을 좋아하면 영구 계정을 만듭니다. SSO 또는 이메일/비밀번호 인증으로 등록합니다. 기본적으로 이렇게 하면 새 User
객체가 생성됩니다. 앱은 새 ID를 원래 사용자와 연결해야 합니다.
LinkCredentialsAsync() 를 사용하여 ID를 연결할 수 있습니다. 이렇게 하면 인증 제공자가 로그인한 사용자 객체 에 연결됩니다.
// 1) A user logs on anonymously: var anonUser = await app.LogInAsync(Credentials.Anonymous()); // 2) They create some data, and then decide they want to save // it, which requires creating an Email/Password account. // 3) We prompt the user to log in, and then use that info to // register the new EmailPassword user, and then generate an // EmailPassword credential to link the existing anonymous // account: var email = "caleb@mongodb.com"; var password = "MySekritPwd"; await app.EmailPasswordAuth.RegisterUserAsync( email, password); var officialUser = await anonUser.LinkCredentialsAsync( Credentials.EmailPassword(email, password));
위의 예시 에서는 연결하기 전에 먼저 새 이메일/비밀번호 사용자를 등록해야 합니다. 다른 인증 제공자 를 사용하는 경우 이 단계가 필요하지 않습니다. 다음 예시 에서는 EmailPassword 대신 Google 인증 을 사용합니다.
var anonUser = await app.LogInAsync(Credentials.Anonymous()); var officialUser = await anonUser.LinkCredentialsAsync( Credentials.Google("<google-token>", GoogleCredentialType.AuthCode));