This demo shows how to implement login and friend systems based on Xsolla Login into an iOS application.
The demo covers this list of scenarios:
- User sign-up via username and password
- Email confirmation
- Password reset
- User authentication via the following social networks:
- Baidu
The demo also shows these following user management features:
- User accounts management
- User attributes customization
- User account system
- Friend system
To try the demo, just build and run this project in Xcode.
Note: The demo requires iOS 11.4 or higher.
All features presented in this demo are based on Xsolla Login library for iOS.
You can use snippets from the demo and library methods to implement your own login and friend systems.
Below are examples of using the basic library methods.
LoginKit.shared.authByUsernameAndPasswordJWT(username: "username",
password: "password",
clientId: AppConfig.loginClientId,
scope: "offline")
{ [weak self] result in
switch result
{
case .success(let accessTokenInfo):
self?.store(accessTokenInfo)
case .failure(let error):
self?.processError(error)
}
}
let oAuth2Params = OAuth2Params(clientId: AppConfig.loginClientId,
state: UUID().uuidString,
scope: "offline",
redirectUri: AppConfig.redirectURL)
LoginKit.shared.getLinkForSocialAuth(providerName: "discord", oauth2params: oAuth2Params)
{ [weak self] result in
switch result
{
case .success(let socialNetworkAuthURL): self?.processSocialNetworkAuthURL(socialNetworkAuthURL)
case .failure(let error): self?.processError(error)
}
}
LoginKit.shared.generateJWT(grantType: .refreshToken,
clientId: AppConfig.loginClientId,
refreshToken: resfreshToken,
clientSecret: nil,
redirectUri: AppConfig.redirectURL,
authCode: nil)
{ [weak self] result in
switch result
{
case .success(let accessTokenInfo):
self?.store(accessTokenInfo)
case .failure(let error):
self?.processError(error)
}
}
let oAuth2Params = OAuth2Params(clientId: AppConfig.loginClientId,
state: UUID().uuidString,
scope: "offline",
redirectUri: AppConfig.redirectURL)
LoginKit.shared.registerNewUser(oAuth2Params: oAuth2Params,
username: "username",
password: "password",
email: "email",
acceptConsent: nil,
fields: nil,
promoEmailAgreement: nil)
{ [weak self] result in
switch result
{
case .success(let urlWithAuthCode):
self?.handleUrlWithAuthCode(urlWithAuthCode)
case .failure(let error):
self?.processError(error)
}
}
LoginKit.shared.resetPassword(loginProjectId: AppConfig.loginProjectID,
username: "username",
loginUrl: AppConfig.redirectURL)
{ [weak self] result in
switch result
{
case .success: break
case .failure(let error): self?.processError(error)
}
}
LoginKit.shared.getCurrentUserDetails(accessToken: currentAccessToken)
{ [weak self] result in
switch result
{
case .success(let userDetails): self?.processUserDetails(userDetails)
case .failure(let error): self?.processError(error)
}
}
LoginKit.shared.uploadUserPicture(accessToken: currentAccessToken, imageURL: imageURL)
{ [weak self] result in
switch result
{
case .success(let uploadedImageURL): break
case .failure(let error): self?.processError(error)
}
}
Join our Discord server. Connect with the Xsolla team and developers who use Xsolla products.
See the LICENSE file.