Git Product home page Git Product logo

account-json-api's People

Contributors

barretodaniel avatar gr2m avatar greenkeeper[bot] avatar lowprofiledog avatar patriciagarcia avatar taekyoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

account-json-api's Issues

Questions about URLs and API response status codes

Hey folks, I have a lot of questions about the API URLs and returned status codes, also, it seems to me that a lot of possible error responses are omitted from the API, so here is a compilations of questions and feedback about the current defined API for further discussion.

Disclaimer: I am focusing first on the "User" (i.e. non admin) part of the API, so this discussion is only about that part.

Session

Sign in PUT /session

Possible responses:

  • session created: 201
  • invalid credentials provided: 401
  • wrong type provided in the request (data.type): 409*
  • a user is logged in already (there is already an active session): ?

Check session GET /session

Possible responses:

  • OK: 200
  • invalid auth header: 401
  • no active session: 401/404?**

Sign out DELETE /session

Possible responses:

  • delete worked: 204
  • invalid auth header: 401
  • no active session: 401/404?**

Account

Sign up PUT /session/account

About the URL:

  • shouldn't that be POST /accounts (this is the URL for admins)
  • it seems weird to me to create a session using PUT /session/account when the session does not exist (since, if the session exist, then we already have an account for it, haven't we?)

Possible responses:

  • account created: 201
  • wrong type provided in the request (data.type): 409*
  • a user is logged in already (there is already an active session, with a corresponding account): ?

Fetch user account GET /session/account

Possible responses:

  • OK: 200
  • invalid auth header: 401
  • no active session: 401/404?**

Change user account PATCH /session/account

Possible responses:

  • OK: 204
  • invalid auth header: 401
  • no active session: 401/404?**
  • updating the user infringes some server-enforced constraints: 409 (this might not be relevant for us)
  • type and id provided in the request don't match (data.type): 409***

Close account DELETE /session/account

Possible responses:

  • OK: 204
  • invalid auth header: 401
  • no active session: 401/404?**

Profile

Fetch profile GET /session/account/profile

Possible responses:

  • OK: 200
  • no profile available: 200 with null as primary data. See JSON API spec.
  • invalid auth header: 401
  • no active session: 401/404?**

Create profile PUT /session/account/profile

Possible responses:

  • profile created: 201
  • invalid auth header: 401
  • no active session: 401/404?**
  • wrong type provided in the request (data.type): 409*
  • a profile is available already: ?

Update profile PATCH /session/account/profile

Possible responses:

  • OK: 204
  • invalid auth header: 401
  • no active session: 401/404?**
  • updating the user infringes some server-enforced constraints: 409 (this might not be relevant for us)
  • type and id provided in the request don't match (data.type): 409***

*This is mentioned in the JSON API spec referring to creating users with POST, I guess it also applies to PUT?

**Some considerations about this one:

  • if there is no active session, then our auth credentials are not the right one, so response should be 401?
  • 404 can be interpreted as: URL doesn't exist, but if the URL doesn't exist, we can't really use PUT for the creation of the resource, can we?

*** See here.

@gr2m, @tthew, @karlwestin comments?

Add route for admins to create user sessions

Follow up for #14

As an admin, I would like to be able to create a user session, so I can debug an account without messing with passwords.

I would suggest the route POST /account/{id}/sessions for that. Without any body (does JSON API allow that?).

The response would look like this:

{
  "links": {
    "self": "https://example.com/accounts/abc1234/sessions/sessionid123"
  },
  "data": {
    "id": "sessionid123",
    "type": "session",
    "relationships": {
      "account": {
        "links": {
          "related": "https://example.com/accounts/abc1234"
        },
        "data": {
          "id": "abc1234",
          "type": "account"
        }
      }
    }
  }
}

This implies that we would also need a GET /accounts/{id}/sessions/{id} and a DELETE /accounts/{id}/sessions/{id} route, which works for me.

Any objections / thoughts?

remove /session/account from spec

Now that I'm implementing the account-json-api spec, I find the /session/account route confusing, because an account can exist and be accessible even without a session. For example, a user can signed up for an account but not sign in until the account is confirmed.

For that reason, I'd suggest to rename /session/account to /account, and /session/account/profile to /account/profile

Update

We now suggest to get rid of /session/account altogether, and use /accounts/{id} instead

SingIn - session[PUT] - shouldn't it be [POST]?

According to this:
http://restcookbook.com/HTTP%20Methods/patch/
"Also, the PUT method is idempotent. PUTting the same data multiple times to the same resource, should not result in different resources, while POSTing to the same resource can result in the creation of multiple resources."

Since the response of this request would have the Created resource (the session), which includes a sessionId. and I think multiple requests would end up with different sessionIds. So using PUT is wrong, and it should be a POST.

change /accounts/<username> routes to /accounts/<id>

I liked the idea of using usernames as IDs in the URLs, but it’s inconsistent with all the rest of our APIs, and could potentially cause issue with JSON API clients.

For example GET /accounts/jane-doe would return

{
    "links": {
        "self": "https://example.com/accounts/jane-doe"
    },
    "data": {
        "id": "def678",
        "type": "account",
        "attributes": {
            "username": "jane-doe",
        }
    },
    "relationships": {
        "profile": {
            "links": {
                "related": "https://example.com/accounts/jane-doe/profile"
            },
            "data": {
                "id": "def678-profile",
                "type": "accountProfile"
            }
        }
    }
}

But data.id is "def678", not "jane-doe". I'm not sure if this is JSON API compliant or not, but when in doubt, I'd rather avoid confusion.

Not using the username in the URLs also prevents issues with weird characters in usernames.


  • start a pr #11
  • make the fix (breaking change)
  • review & merge

Remove Account Update Route

I think we can remove the PATCH /session/account route entirely, and make all account properties after sign up read only, without exception. The security requirements / workflows to change a username or a password are app-specific, so I'd suggest that we use the requests API for that. I think it's perfectly suited for that.

In Hoodie’s implementation, the handlers for the different requests can be defined with requests option passed to the hapi plugin. For example the following request handler would require a x-password header to be sent, and the PUT request against CouchDB would happen with basic auth, using the username and password, and will therefore fail if the password is incorrect. The user's session is ignored entirely.

var options = {
  /// ...
  requests: {
    updateAccount: function (request, reply) {
      var server = request.connection.server
      var user = request.auth.credentials
      var password = request.headers['x-password']

      var promise = server.plugins.account.api.accounts.update(user.id, {
        username: request.payload.username,
        password: request.payload.password
      }, {
        auth: {
          username: user.username,
          password: password
        }
      })

      reply(promise)
    }
  }
}

That would also make the separation of accounts & profiles more clear.

Any thoughts @patriciagarcia @tthew?

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.