User authentication
// use session object to make API calls
// sent request to get confirmation code
val sentCode: TLSentCode =
session.callEnsure(TLSendCode(phone, TLAuthCodeDeliveryTypeSMS(), "en", "")).get()
// authorize with confirmation code
val authorizeAccount = TLAuthorizeAccount(
phone,
sentCode.phoneCodeHash,
"55786", // sms code
""
)
authorization = session.callEnsure(authorizeAccount).get()
// every authorization is constrained to organizations scope
// and authorized-context request should be made with organization id
val orgId = ORG_RID
val orgToken =
authorization?.account?.users?.first { it is TLUserSelf && it.organizationId == orgId }
.let { it as TLUserSelf }.organizationToken
if (orgToken != null) {
// example - how to get user state with org-scoped request
val state: TLUserState = session.callOrgEnsure(orgId, orgToken, TLGetUserState()).get()
isAuthorized = true
}Last updated
