forked from Brightspace/D2L.Security.OAuth2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: return detailed error messages for WebApi integration
Closes: Brightspace#40
- Loading branch information
Showing
16 changed files
with
260 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/D2L.Security.OAuth2.WebApi/Authorization/Exceptions/InsufficientScopeException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using D2L.Security.OAuth2.Scopes; | ||
|
||
namespace D2L.Security.OAuth2.Authorization.Exceptions { | ||
internal sealed class InsufficientScopeException : OAuth2Exception { | ||
|
||
internal InsufficientScopeException( Scope scope, Exception innerException = null ) : base( | ||
error: OAuth2Exception.Type.insufficient_scope, | ||
errorDescription: $"Required scope: '{ scope }'", | ||
innerException: innerException | ||
) { | ||
Scope = scope; | ||
} | ||
|
||
internal Scope Scope { get; } | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/D2L.Security.OAuth2.WebApi/Authorization/Exceptions/OAuth2Exception.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace D2L.Security.OAuth2.Authorization.Exceptions { | ||
internal class OAuth2Exception : Exception { | ||
// Note: the naming style of these enum values matches the codes from RFC6750 | ||
public enum Type { | ||
invalid_request = HttpStatusCode.BadRequest, | ||
invalid_token = HttpStatusCode.Unauthorized, | ||
insufficient_scope = HttpStatusCode.Forbidden | ||
} | ||
|
||
internal OAuth2Exception( | ||
Type error, | ||
string errorDescription, | ||
Exception innerException = null | ||
) : base( | ||
message: $"{ error }: { errorDescription }", | ||
innerException: innerException | ||
) { | ||
Error = error; | ||
ErrorDescription = errorDescription; | ||
|
||
if( errorDescription.Contains( "\"" ) ) { | ||
throw new ArgumentException( nameof( errorDescription ), "Must not contain '\"' character" ); | ||
} | ||
} | ||
|
||
public Type Error { get; } | ||
public string ErrorDescription { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/D2L.Security.OAuth2.WebApi/Authorization/OAuth2ErrorResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace D2L.Security.OAuth2.Authorization { | ||
internal sealed class OAuth2ErrorResponse { | ||
|
||
public OAuth2ErrorResponse( | ||
string error, | ||
string errorDescription | ||
) { | ||
Error = error; | ||
ErrorDescription = errorDescription; | ||
} | ||
|
||
[JsonProperty( "error", Required = Required.Always )] | ||
public string Error { get; } | ||
|
||
[JsonProperty( "error_description", Required = Required.Always )] | ||
public string ErrorDescription { get; } | ||
|
||
[JsonProperty( "scope" )] | ||
public string Scope { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.