GithubHelp home page GithubHelp logo

qlcdfork / casdoor-ios-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from casdoor/casdoor-ios-sdk

0.0 0.0 0.0 193 KB

Casdoor iOS client SDK (in Swift)

Home Page: https://github.com/casdoor/casdoor

License: Apache License 2.0

Swift 100.00%

casdoor-ios-sdk's Introduction

casdoor-ios-sdk

Casdoor's SDK for iOS will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch. Casdoor SDK is simple to use. We will show you the steps below.

Step0. Adding the dependency

.package(url: "https://github.com/casdoor/casdoor-ios-sdk.git", from: "x.x.x")

and Casdoor dependency to your target:

.target(
   name: "MyApp", 
   dependencies: [
       .product(name: "Casdoor", package: "casdoor-ios-sdk")
    ]
 ),

Step1. Init Config

Initialization requires 5 parameters, which are all str type:

Name (in order) Must Description
endpoint Yes Casdoor Server Url, such as http://localhost:8000
clientID Yes Application.clientID
appName Yes Application.name
apiEndpoint NO Casdoor Api Url, default endpoint + "/api/"
organizationName Yes Organization name
let config:CasdoorConfig = .init(
            endpoint: "http://localhost:8000",
            clientID: "ced4d6db2f4644b85a75",
            organizationName: "organization_6qvtvh",
            redirectUri: "casdoor://callback",
            appName: "application_y38644",
     )

Step2. Init Casdoor

The Casdoor Contains all APIs

let casdoor:Casdoor = .init(config:config)

Step3. Authorize with the Casdoor server

At this point, we should use some ways to verify with the Casdoor server.

To start, we want you understand clearly the verification process of Casdoor. The following paragraphs will mention your app that wants to use Casdoor as a means of verification as APP, and Casdoor as Casdoor. APP will send a request to Casdoor. Since Casdoor is a UI-based OAuth provider, you cannot use request management service like Postman to send a URL with parameters and get back a JSON file.

casdoor-ios-sdk support the url,you can use in webview or safariView

casdoor.getSigninUrl(scope:nil,state:nil)

Hints:

  1. redirect_uri is the URL that your APP is configured to listen to the response from Casdoor. For example, if your redirect_uri is casdoor://callback, then Casdoor will send a request to this URL along with two parameters code and state, which will be used in later steps for authentication.
  2. state is usually your Application's name, you can find it under the Applications tab in Casdoor, and the leftmost Name column gives each application's name.
  3. The authorize URL allows the user to connect to a provider and give access to your application.You can use WKWebView,SFSafariViewController or ASWebAuthenticationSession if you want.
  4. After Casdoor verification passed, it will be redirected to your redirect_uri, like casdoor://callback?code=xxx&state=yyyy.you can catch it and get the code and state, then call requestOauthAccessToken(code:,state:) and parse out jwt token.

Example

See at: https://github.com/casdoor/casdoor-ios-example

casdoor-ios-sdk's People

Contributors

xiaobeiswift avatar hsluoyz avatar

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.