Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Add sanity check to make OAuth route friendlier
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed Jul 11, 2017
1 parent c5dc7aa commit 76c7407
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ public OauthInvalidRequest()
error = "invalid_request"
};
}

public OauthInvalidRequest(string errorDescription)
{
Body = new
{
error = "invalid_request",
error_description = errorDescription
};
}
}
}
6 changes: 6 additions & 0 deletions src/Stormpath.Owin.Middleware/Route/Oauth2Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ private async Task<bool> ExecutePasswordFlow(IOwinEnvironment context, string us
var jsonErrorHandler = new Func<string, CancellationToken, Task>((message, ct)
=> Error.Create(context, new BadRequest(message), ct));

if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
await Error.Create(context, new OauthInvalidRequest("Missing username or password"), cancellationToken);
return true;
}

var (grantResult, user) = await executor.PasswordGrantAsync(
context,
jsonErrorHandler,
Expand Down

0 comments on commit 76c7407

Please sign in to comment.