Git Product home page Git Product logo

kitura-credentialshttp's Introduction

Kitura

A Swift Web Framework and HTTP Server

Docs Build Status - Master macOS Linux Apache 2 codecov codebeat badge Slack Status

Summary

Kitura is a web framework and web server that is created for web services written in Swift. For more information, visit www.kitura.dev.

Table of Contents

Features

  • URL routing (e.g., GET, POST, PUT, DELETE, PATCH)
  • Codable routing
  • URL parameters
  • Static file serving
  • FastCGI support
  • SSL/TLS support
  • Pluggable middleware

Getting Started

Visit https://www.kitura.dev for a Getting Started guide, tutorials, and API reference documentation.

Contributing to Kitura

All improvements to Kitura are very welcome! Here's how to get started with developing Kitura itself.

  1. Clone this repository.

$ git clone https://github.com/Kitura/Kitura

  1. Build and run tests.

$ swift test

You can find more info on contributing to Kitura in our contributing guidelines.

Notes

  • Swift-NIO is now the default network engine via the Kitura-NIO package. If for some reason you require the old Kitura-net package, you can still enable it by setting an environment variable KITURA_NIO=0 during build.
  • Most Kitura packages have been updated to require at least Swift 5.2 in order to maintain backward compatibility.

Community

We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!

kitura-credentialshttp's People

Contributors

andrew-lees11 avatar bdhernand avatar carlbrown avatar dannys42 avatar dfirsht avatar djones6 avatar drewmccormack avatar gmosx avatar gtaban avatar helenmasters avatar ianpartridge avatar irar2 avatar jarrodparkes avatar kyemaloy97 avatar mbarnach avatar na-gupta avatar quanvo87 avatar rolivieri avatar shihabmehboob avatar shmuelk avatar vadimeisenbergibm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kitura-credentialshttp's Issues

Incorrect handling of password containing colon in HTTP Basic Authentication.

In HTTP Basic Auth, although a username may not contain a colon, a password may. At this point, Kitura authentication fails when supplying a password containing a colon.

The lines in question seem to be here:
https://github.com/IBM-Swift/Kitura-CredentialsHTTP/blob/660c43cf11da63561e45dd14d805c34041bd73fa/Sources/CredentialsHTTP/CredentialsHTTPBasic.swift#L110-L117

The password is set to be the second item in the components (after separating by colons), but actually, the password should be all items after the first, joined by colons. So...

user:pass:with:some:colons

User is item 0. Pass is 1...4 joined by : characters, namely pass:with:some:colons.

Authenticating specific resources?

What's the recommended way to authenticate for specific resources using HTTP Basic Auth?

For example, suppose I have an endpoint to POST a message for a certain conversation:

router.post("/messages") { (request, response, next) in
    // Extract conversation UUID from request body...
    let uuid = UUID_FROM_BODY
    // Post the message for this conversation, etc...
    // Respond to client
    response.status(.accepted) 
}

But only certain users are authorized to POST for certain conversations. A UserProfileLoader allows me to check for the existence of a user and confirm their password, but how can I confirm that they have access to a specific resource? E.g. in the example above, I would need to pass the conversation UUID to a UserProfileLoader function in addition to the userId.

HTTP Basic Auth is providing unauthorized access to protected resources.

I'm working on setting up HTTP Basic Auth and I think I may have found a nasty bug. When I go to the OpenAPI UI and access one of the protected routes, I get the username and password prompt as expected. When I enter an incorrect username and password, the prompt reappears so I can try again with different credentials (expected). The issue is that if I hit the cancel button on the prompt, the server returns a 401 HTTP Status code (expected), but also returns the data that they are not authorized to access (unexpected).

Here is how I setup the Basic Auth:

func initializeBasicAuth(app: App) {
    let credentials = Credentials()
    
    let basicCredentials = CredentialsHTTPBasic(verifyPassword: { username, password, callback in
        UserAuth.authEntry(username: username, onCompletion: { (authMatches, error) in
            if let entries = authMatches, let userAuth = entries.first {
                
                // Check Password
                let saltedPassword = "\(password)\(userAuth.salt)"
                let hashedPassword = hashPassword(saltedPassword)
                
                if hashedPassword == userAuth.hashedPassword {
                    let userProfile = UserProfile(id: userAuth.username,
                                                  displayName: username,
                                                  provider: "HTTPBasic")
                    callback(userProfile)
                } else {
                    callback(nil)
                }
            } else {
                callback(nil)
            }
        })
    })
    
    credentials.register(plugin: basicCredentials)
    app.router.get("/entries", middleware: credentials)
    app.router.put("/entries", middleware: credentials)
    app.router.delete("/entries", middleware: credentials)
}

So if I use the OpenAPI UI to perform a GET request on the /entries endpoint, I still get the JSON data back in the body of the response along with the 401 HTTP Status code in the headers.

fatal error CredentialsHTTPBasic.swift:96 on wrong headers

If the Authorisation Header is not correct the whole app is crashing. As this is a server add-on, it should fail silently and not crash.

So there should be a check on whether authorizationComponents array has at least 2 items, before accessing the items.

Can I custom the login page?

Hi master,
I hava a simple question about the login page.
Can I customize the login page and how?
example: the user name placeholder instead of email.
Thanks.

VerifyPassword should use an escaping closure

Issue descriptioon

VerifyPassword is currently defined as follows (with a nonescaping closure for UserProfile):
public typealias VerifyPassword = (String, String, (UserProfile?)->Void) -> Void

However, when using e.g. Kuery for doing DB lookups to verify passwords from a database, DB query functions are escaping. This results in code like the following example:

let basicCredentials = CredentialsHTTPBasic( verifyPassword: { userID, password, callback in
    let query = Select(users.email, users.password, from: users)
        .where(users.email == userID)

    connection.execute(query: query) { result in
        if let rows = result.asRows {
            if let truePassword = rows[0]["password"] as? String {
                if truePassword == password {
                    callback(UserProfile(id: userID, displayName: userID, provider: "HTTPBasic-Kitura"))
                    return
                }
            }
        callback(nil)
    }
})

In this case the Swift Complier will generate an error:

Closure use of non-escaping parameter 'callback' may allow it to escape

Suggested fix

Change VerifyPassword typealias to use an explicitly escaping closure:

public typealias VerifyPassword = (String, String, @escaping(UserProfile?)->Void) -> Void

ld: library not found for -lCHttpParser for architecture x86_64

I stabled upon this issue when added CredentialsHTTP as dependency to my Kitura project. Basically solution to get this working is same as proposed on main Kitura project in Troubleshooting section
I think this should be added to README.md

Troubleshooting
Seeing error ld: library not found for -lCHttpParser for architecture x86_64 on build:

To solve this, go to your build settings and add $SRCROOT/.build/debug to the Library Search Paths for the CredentialsHTTP targets.

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.