Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More advanced control for encoders, parsers and url builders #30

Merged
merged 2 commits into from
Jun 30, 2021

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Jun 29, 2021

ℹ️ Allow more advanced control for tweaking parsers, decoders and url builders. This is particularly useful for applications integrating with systems which are either not strictly following the OAuth2.0 specifications, or, systems who introduce custom fields of some importance for the underlying application. (see #29, #23, #21)

OAuth - MINOR

  • Added:

    type GrantType
        = AuthorizationCode
        | Password
        | ClientCredentials
        | RefreshToken
        | CustomGrant String
    
    grantTypeToString : GrantType -> String
    type ResponseType
        = Code
        | Token
        | CustomResponse String
    
    responseTypeToString : ResponseType -> String

OAuth.Implicit - MAJOR

  • Added:

    makeAuthorizationUrlWith :
        ResponseType
        -> Dict String String
        -> Authorization
        -> Url
  • Changed:

    -- type alias Parsers =
    --     { tokenParser :
    --           Query.Parser (Maybe Token)
    --     , errorParser :
    --           Query.Parser (Maybe ErrorCode)
    --     , authorizationSuccessParser :
    --           String -> Query.Parser AuthorizationSuccess
    --     , authorizationErrorParser :
    --           ErrorCode -> Query.Parser AuthorizationError
    --     }
    
    type alias Parsers error success =
        { tokenParser :
              Query.Parser (Maybe Token)
        , errorParser :
              Query.Parser (Maybe ErrorCode)
        , authorizationSuccessParser :
              String -> Query.Parser success
        , authorizationErrorParser :
              ErrorCode -> Query.Parser error
        }
    -- defaultParsers : Parsers
    defaultParsers : Parsers AuthorizationError AuthorizationSuccess
    -- parseTokenWith : Parsers -> Url -> AuthorizationResult
    parseTokenWith : Parsers error success -> Url -> AuthorizationResultWith error success

OAuth.AuthorizationCode - MAJOR

  • Added:

    makeAuthorizationUrlWith :
        ResponseType
        -> Dict String String
        -> Authorization
        -> Url
    makeTokenRequestWith :
        OAuth.GrantType
        -> Json.Decoder success
        -> Dict String String
        -> (Result Http.Error success -> msg)
        -> Authentication
        -> RequestParts msg
  • Changed:

    -- type AuthorizationResult
    --     = Empty
    --     | Error AuthorizationError
    --     | Success AuthorizationSuccess
    
    type alias AuthorizationResult =
        AuthorizationResultWith AuthorizationError AuthorizationSuccess
    
    type AuthorizationResultWith error success
        = Empty
        | Error error
        | Success success
    -- type alias Parsers =
    --     { codeParser :
    --           Query.Parser (Maybe String)
    --     , errorParser :
    --           Query.Parser (Maybe ErrorCode)
    --     , authorizationSuccessParser :
    --           String -> Query.Parser AuthorizationSuccess
    --     , authorizationErrorParser :
    --           ErrorCode -> Query.Parser AuthorizationError
    --     }
    
    type alias Parsers error success =
        { codeParser :
              Query.Parser (Maybe String)
        , errorParser :
              Query.Parser (Maybe ErrorCode)
        , authorizationSuccessParser :
              String -> Query.Parser success
        , authorizationErrorParser :
              ErrorCode -> Query.Parser error
        }
    -- defaultParsers : Parsers
    defaultParsers : Parsers AuthorizationError AuthorizationSuccess
    -- parseCodeWith : Parsers -> Url -> AuthorizationResult
    parseCodeWith : Parsers error success -> Url -> AuthorizationResultWith error success

OAuth.AuthorizationCode.PKCE - MAJOR

  • Added:

    makeAuthorizationUrlWith :
        ResponseType
        -> Dict String String
        -> Authorization
        -> Url
    makeTokenRequestWith :
        OAuth.GrantType
        -> Json.Decoder success
        -> Dict String String
        -> (Result Http.Error success -> msg)
        -> Authentication
        -> RequestParts msg
  • Changed:

    -- type AuthorizationResult
    --     = Empty
    --     | Error AuthorizationError
    --     | Success AuthorizationSuccess
    
    type alias AuthorizationResult =
        AuthorizationResultWith AuthorizationError AuthorizationSuccess
    
    type AuthorizationResultWith error success
        = Empty
        | Error error
        | Success success
    -- type alias Parsers =
    --     { codeParser :
    --           Query.Parser (Maybe String)
    --     , errorParser :
    --           Query.Parser (Maybe ErrorCode)
    --     , authorizationSuccessParser :
    --           String -> Query.Parser AuthorizationSuccess
    --     , authorizationErrorParser :
    --           ErrorCode -> Query.Parser AuthorizationError
    --     }
    
    type alias Parsers error success =
        { codeParser :
              Query.Parser (Maybe String)
        , errorParser :
              Query.Parser (Maybe ErrorCode)
        , authorizationSuccessParser :
              String -> Query.Parser success
        , authorizationErrorParser :
              ErrorCode -> Query.Parser error
        }
    -- defaultParsers : Parsers
    defaultParsers : Parsers AuthorizationError AuthorizationSuccess
    -- parseCodeWith : Parsers -> Url -> AuthorizationResult
    parseCodeWith : Parsers error success -> Url -> AuthorizationResultWith error success

OAuth.ClientCredentials - MINOR

  • Added:

    makeTokenRequestWith :
        GrantType
        -> Json.Decoder success
        -> Dict String String
        -> (Result Http.Error success -> msg)
        -> Authentication
        -> RequestParts msg

OAuth.Password - MINOR

  • Added:

    makeTokenRequestWith :
        GrantType
        -> Json.Decoder success
        -> Dict String String
        -> (Result Http.Error success -> msg)
        -> Authentication
        -> RequestParts msg

OAuth.Refresh - MINOR

  • Added:

    makeTokenRequestWith :
        GrantType
        -> Json.Decoder success
        -> Dict String String
        -> (Result Http.Error success -> msg)
        -> Authentication
        -> RequestParts msg

KtorZ added 2 commits June 29, 2021 21:55
  This allows to tweak even more decoders and parsers for all
  grants, giving developers the ability to add extra fields to URL, or,
  to define their own results types (and parsers for those).

  It is introduced as a small breaking-change because of a change on the
  parser type, which is now parameterized by the error and success
  types. Other than that, it's pretty much drop-in.
@adrianbunea
Copy link

Just what I needed, it was easy to migrate to the new version. Thanks!

@KtorZ KtorZ merged commit 371069f into master Jun 30, 2021
@KtorZ KtorZ deleted the KtorZ/more-advanced-control-encoders-and-parsers branch June 30, 2021 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants