Giter VIP home page Giter VIP logo

appid-serversdk-swift's People

Contributors

aal80 avatar andrew-lees11 avatar antonaleksandrov avatar djones6 avatar gtaban avatar hendriku avatar ianpartridge avatar icemann92 avatar ishangulhane avatar kimmytaft avatar kyemaloy97 avatar mnsn avatar motyd avatar rolivieri avatar sandmman avatar shiranyo avatar talaviel avatar tfrank64 avatar tunniclm avatar vitalymibm avatar yuvalzymerman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appid-serversdk-swift's Issues

Remove SwiftyJSON

This library is (we think) the last IBM Swift package to depend on SwiftyJSON.

SwiftyJSON has been obsolete since Swift 4 in 2017, when Codable and JSONEncoder were introduced.

Unfortunately this package exposes SwiftyJSON types in its public API, so removing SwiftyJSON will be SemVer Major.

SwiftyJSON currently does not currently support Swift 5.1 so unless this is fixed this package cannot support Swift 5.1.

Test cases failing due to XCTAssertEqual failure

I just cloned and compiled the project and ran swift test but there are 4 failures due to XCTAssertEquals failing to compare to two values.

From the output its a mismatch due to the redirect URI expecting "...http:%2F%2F..." but the test returns a %3A instead of a : so it would return "...http%3A%2F%2F..." which causes it to fail.

Unable to retrieve token.

Running https://github.com/IBM-Swift/Kitura-Sample project using provided Dockerfiles and instructions I try to login using App ID.

I press the button and get redirected to my App ID login page, I fill in the email and password, and get redirected back to login fail url.

The output it the console is:

[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: handleAuthorization
[DBG] [WebAppKituraCredentialsPlugin] AUTHURL: ...
[DBG] [WebAppKituraCredentialsPlugin] Redirecting to : ...
[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: retrieveTokens
[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: Failed to obtain tokens. error message : Error HTTP Response: 500
status code : 500
token body : Optional(149 bytes)

After digging down a bit trying to find the origin of the error I found a method inside WebAppKituraCredentialsPlugin

fileprivate func retrieveTokens(options: [String: Any],
                                grantCode: String,
                                onFailure: @escaping (HTTPStatusCode?, [String: String]?) -> Void,
                                request: RouterRequest,
                                onSuccess: @escaping (UserProfile) -> Void) {
        logger.debug("WebAppKituraCredentialsPlugin :: retrieveTokens")

        guard let clientId = config.clientId,
              let secret = config.secret,
              let serverUrl = config.serverUrl else {

                onFailure(nil, nil)
                return
        }

        let tokenEndpoint = serverUrl + Constants.Endpoints.token
        let redirectUri = config.redirectUri
        let authorization = clientId + ":" + secret

        let restReq = RestRequest(method: .post, url: tokenEndpoint, containsSelfSignedCert: false)
        restReq.headerParameters = ["Authorization": "basic " + Data(authorization.utf8).base64EncodedString()]
        let params = [ "client_id": clientId,
                       "grant_type": "authorization_code",
                       "redirect_uri": redirectUri,
                       "code": grantCode ]
        if let json = try? JSONSerialization.data(withJSONObject: params, options: []) {
            restReq.messageBody = json
        } else {
            logger.debug("Failed to parse data into JSON.")
        }

        restReq.response { (tokenData, tokenResponse, tokenError) in
            self.handleTokenResponse(httpCode: tokenResponse?.statusCode,
                                     tokenData: tokenData,
                                     tokenError: tokenError,
                                     originalRequest: request,
                                     onFailure: onFailure,
                                     onSuccess: onSuccess)
        }
    }

Everything look fine up until:

restReq.response { (tokenData, tokenResponse, tokenError) in
   ...
}

which returns empty tokenData, and an error:

po tokenError!.localizedDescription
"The operation couldn’t be completed. (SwiftyRequest.RestError error 0.)"

So it looks like WebAppKituraCredentials request to App ID server generates a 500 error.

Add SwiftyJSON support explicitly

Kitura-Credentials has removed its dependency on SwiftyJSON and without an explicit package declaration, there is no longer SwiftyJSON package access.

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.