<commit_before>part of monadart;

class AuthController<ResourceOwner extends Authenticatable, TokenType extends Tokenizable> extends HttpController {
  static String get RoutePattern => "/auth/token";

  AuthenticationServer<ResourceOwner, TokenType> authenticationServer;

  AuthController(AuthenticationServer<ResourceOwner, TokenType> authServer) {
    authenticationServer = authServer;
    acceptedContentTypes = [new ContentType("application", "x-www-form-urlencoded")];
  }

  /// Creates or refreshes an authentication token.
  ///
  /// Content-Type must be application/x-www-form-urlencoded. (Query string in the body, e.g. username=bob&password=password)
  /// Values must be URL percent encoded by client.
  /// When grant_type is 'password', there must be username and password values.
  /// When grant_type is 'refresh', there must be a refresh_token value.
  @httpPost
  Future<Response> create({String grant_type, String username, String password, String refresh_token}) async {
    var authorizationHeader = request.innerRequest.headers[HttpHeaders.AUTHORIZATION]?.first;

    var rec = new AuthorizationBasicParser(authorizationHeader);
    if (grant_type == "password") {
      if (username == null || password == null) {
        return new Response.badRequest(body: {"error": "username and password required"});
      }

      var token = await authenticationServer.authenticate(username, password, rec.username, rec.password);
      return AuthController.tokenResponse(token);
    } else if (grant_type == "refresh") {
      if (refresh_token == null) {
        return new Response.badRequest(body: {"error": "missing refresh_token"});
      }
<commit_msg>Added authorization info to authcontroller docs<commit_after>part of monadart;

class AuthController<ResourceOwner extends Authenticatable, TokenType extends Tokenizable> extends HttpController {
  static String get RoutePattern => "/auth/token";

  AuthenticationServer<ResourceOwner, TokenType> authenticationServer;

  AuthController(AuthenticationServer<ResourceOwner, TokenType> authServer) {
    authenticationServer = authServer;
    acceptedContentTypes = [new ContentType("application", "x-www-form-urlencoded")];
  }

  /// Creates or refreshes an authentication token.
  ///
  /// Authorization header must contain Basic authorization scheme where username is Client ID and password is Client Secret,
  /// e.g. Authorization: Basic base64(ClientID:ClientSecret)
  /// Content-Type must be application/x-www-form-urlencoded. (Query string in the body, e.g. username=bob&password=password)
  /// Values must be URL percent encoded by client.
  /// When grant_type is 'password', there must be username and password values.
  /// When grant_type is 'refresh', there must be a refresh_token value.
  @httpPost
  Future<Response> create({String grant_type, String username, String password, String refresh_token}) async {
    var authorizationHeader = request.innerRequest.headers[HttpHeaders.AUTHORIZATION]?.first;

    var rec = new AuthorizationBasicParser(authorizationHeader);
    if (grant_type == "password") {
      if (username == null || password == null) {
        return new Response.badRequest(body: {"error": "username and password required"});
      }

      var token = await authenticationServer.authenticate(username, password, rec.username, rec.password);
      return AuthController.tokenResponse(token);
    } else if (grant_type == "refresh") {
      if (refresh_token == null) {
        return new Response.badRequest(body: {"error": "missing refresh_token"});
      }

{'fraction_non_alphanumeric': 0.10262863534675615, 'fraction_numerical': 0.0005592841163310962, 'mean_word_length': 4.395173453996984, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5975705', 'n_tokens_mistral': 925, 'n_tokens_neox': 896, 'n_words': 288}