Authlete
|
Access token validator. More...
Public Member Functions | |
AccessTokenValidator (IAuthleteApi api) | |
Constructor. More... | |
async Task< bool > | Validate (string accessToken, string[] requiredScopes=null, string requiredSubject=null) |
Validate an access token. More... | |
Properties | |
Boolean | IsValid [get] |
The flag whether the access token given to Validate() is valid or not. After a call of Validate() method, this property holds the same value returned from Validate() . More... | |
IntrospectionResponse | IntrospectionResult [get] |
A response from Authlete's /api/auth/introspection API. Validate() method internally calls /api/auth/introspection API and sets the response to this property. Note that this property remains null if the API call threw an exception, and in that error case, the IntrospectionError property is set. More... | |
Exception | IntrospectionError [get] |
Validate() method internally calls Authlete's /api/auth/introspection API. If the API call threw an exception, the exception would be set to this property. Note that this property remains null if the API call succeeded, and in that successful case, the IntrospectionResult property is set. More... | |
HttpResponseMessage | ErrorResponse [get] |
An error response that the API caller (here assuming that the API caller is an implementation of a protected resource endpoint) should return to the client application. This property is internally set by Validate() method when Validate() returns false . The error response complies with RFC 6750 (The OAuth 2.0 Authorization Framework: Bearer Token Usage). More... | |
Access token validator.
Since version 1.0.7.
|
inline |
Constructor.
api | An implementation of the IAuthleteApi interface. This is required because Validate() method internally calls Authlete's /api/auth/introspection API. |
|
inline |
Validate an access token.
On entry, as the first step, the implementation of this method resets the following properties to false
or null
.
IsValid
IntrospectionResult
IntrospectionError
ErrorResponse
Then, this method internally calls Authlete's /api/auth/introspection
API to get information about the access token.
If the API call failed, the exception thrown by the API call is set to the IntrospectionError
property and an error response (500 Internal Server Error)
that should be returned to the client application is set to the ErrorResponse
property. Then, this method sets false
to the IsValid
property and returns false
.
If the API call succeeded, the response from the API is set to the IntrospectionResult
property. Then, the implementation of this method checks the value of the "action"
parameter in the response from the API.
If the value of the "action"
parameter is "OK"
, this method sets true
to the IsValid
property and returns true
.
If the value of the "action"
parameter is not "OK"
, this method builds an error response that should be returned to the client application and sets it to the ErrorResponse
property. Then, this method sets false
to the IsValid
property and returns false
.
requiredScopes
was given) and the access token is associated with the required subject (in case requiredSubject
was given), this method returns true
. In other cases, this method returns false
. accessToken | An access token to be validated. |
requiredScopes | Scopes that the access token should have. If a non-null value is given to this parameter, the implementation of Authlete's /api/auth/introspection API checks whether the access token covers all the required scopes. On the other hand, if null is given to this parameter, Authlete does not conduct the validation. |
requiredSubject | Subject (= unique identifier of an end-user) that the access token should be associated with. If a non-null value is given to this parameter, the implementation of Authlete's /api/auth/introspection API checks whether the access token is associated with the required subject. On the other hand, if null is given to this parameter, Authlete does not conduct the validation. |
|
get |
An error response that the API caller (here assuming that the API caller is an implementation of a protected resource endpoint) should return to the client application. This property is internally set by Validate()
method when Validate()
returns false
. The error response complies with RFC 6750 (The OAuth 2.0 Authorization Framework: Bearer Token Usage).
On entry of Validate()
method, this property is reset to null
.
|
get |
Validate()
method internally calls Authlete's /api/auth/introspection
API. If the API call threw an exception, the exception would be set to this property. Note that this property remains null
if the API call succeeded, and in that successful case, the IntrospectionResult
property is set.
On entry of Validate()
method, this property is reset to null
.
|
get |
A response from Authlete's /api/auth/introspection
API. Validate()
method internally calls /api/auth/introspection
API and sets the response to this property. Note that this property remains null
if the API call threw an exception, and in that error case, the IntrospectionError
property is set.
On entry of Validate()
method, this property is reset to null
.
|
get |
The flag whether the access token given to Validate()
is valid or not. After a call of Validate()
method, this property holds the same value returned from Validate()
.
On entry of Validate()
method, this property is reset to false
.