Giter VIP home page Giter VIP logo

login-ios-demo's Introduction

Xsolla Login demo app for iOS

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:
    • Google
    • Facebook
    • Twitter
    • LinkedIn
    • Baidu

Demo Login page

Demo Sign up page

The demo also shows these following user management features:

  • User accounts management
  • User attributes customization
  • User account system
  • Friend system

Demo attributes page

DDemo User Account page

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.

Receive access token by username and password

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)
    }
}

Authenticate user via social network

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)
    }
}

Generate JWT

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)
    }
}

Register new user

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)
    }
}

Reset password

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)
    }
}

Get details of current authenticated user

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)
    }
}

Upload user avatar

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)
    }
}

Community

Join our Discord server. Connect with the Xsolla team and developers who use Xsolla products.

License

See the LICENSE file.

Additional resources

login-ios-demo's People

Contributors

gussent avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.