1.0.9 • Published 10 months ago

aponia v1.0.9

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Aponia Auth

Concepts

User

  • Literally the user information.

Session

  • The information stored in an access token.
  • Used to get a user. Examples...
    • The user itself, i.e. token-based approach.
    • Just the user's session ID, i.e. database-based approach.

Access Token

  • A JWT, encrypted string that's stored in a cookie

Refresh Token

  • A JWT, encrypted string that's used to refresh a user's session.

Auth Approaches

Token-Based

  • Store the user in the access token.
  • To identify the user of a request, just decode the access token cookie.
  • To renew a session, use the data in the refresh token to generate new tokens.

Database-Based

  • Store only the user's session ID in the access token.
  • The database should have a corresponding session with an expiration date
  • To identify the user of a request, decode the access token cookie and look up the session ID in a database.
  • To renew a session, use the data in the refresh token to modify the database (i.e. changing the session's expiration date or just creating a new one) and then generate tokens

Ideas for Refresh Tokens

Note: Because the refresh token is JWT + encrypted, a successful decode means that it was initially created by you.

The user or user ID.

After successfully decoding the refresh token and getting some user info, you can use that info to generate another access token. And you'd probably use the same refresh token data (i.e. same user ID or user info) with a new expiration date.

The session ID.

You can also store the session ID in a refresh token (i.e. both access and refresh tokens might have the same data). The main difference between the tokens in this case is that the access token has a shorter lifespan. The session ID can be decoded from the refresh token, and the corresponding session found in the database. Then the sesion can be extended or a new session can be created. Take the resultant session's ID and put them back into tokens.

Life-Cycle

  1. Initialize the Auth class
  • It can generally handle static auth routes.
  1. An incoming Request object is converted to an InternalRequest
  2. If the request is for a static auth URL, then the Auth class handles it directly and returns.
  • e.g. /auth/logout, /auth/forgot, /auth/reset etc.
  • They're considered static because those routes aren't inherently associated with a provider.
  • i.e. Google doesn't send you a reset-password link for your own website...that's your job.
  1. If the request is for a provider, then the Auth class delegates it to the provider, but doesn't return yet!
  • Internally, each provider stores a map of the routes it will handle, which is configurable!
  • e.g. /auth/login/github, /auth/callback/github
  • The base Auth class simply reads these routes, and then creates a Map that connects the auth route string with the provider class.
  • Then when a match is found, the Auth class will invoke the proper method on the provider.
  • i.e. If /auth/login/github matched with the request URL, then the GitHub provider was found in the Map and its login method will be invoked.
  1. If a user was created during the provider request, i.e. after logging in with OAuth, then the session managers's createSession handler is invoked with the user.
  2. Finally the handling is done.

Objects / Methods

User

A user represents the identified user for the current request. Generally won't be defined, and lazily evaluated with getUser.

getUser

Checks the request to see if user is defined. If not, then... 1. Decode the access token from cookies 2. Invoke the session manager's getUserFromSession. Remember, the user and session aren't always the same! 3. Save the user into the request. 4. Return the user.

1.0.9

10 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.1.52

11 months ago

0.1.53

11 months ago

0.1.51

11 months ago

0.1.45

12 months ago

0.1.46

12 months ago

0.1.47

12 months ago

0.1.44

1 year ago

0.1.43

1 year ago

0.1.42

1 year ago

0.1.41

1 year ago

0.1.40

1 year ago

0.1.39

1 year ago

0.1.38

1 year ago

0.1.37

1 year ago

0.1.36

1 year ago

0.1.35

1 year ago

0.1.34

1 year ago

0.1.33

1 year ago

0.1.32

1 year ago

0.1.31

1 year ago

0.1.30

1 year ago

0.1.25

1 year ago

0.1.24

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago