Class TokenService
- Namespace
- Dynamicweb.Security.Tokens
- Assembly
- Dynamicweb.Core.dll
Service to working with tokens.
public sealed class TokenService
- Inheritance
-
TokenService
- Inherited Members
Methods
AuthenticateOAuthClient(string, string)
Authenticates an OAuth client by validating clientId and clientSecret.
public static User? AuthenticateOAuthClient(string clientId, string clientSecret)
Parameters
clientIdstringThe client ID (stored in cleartext).
clientSecretstringThe plaintext client secret to validate.
Returns
AuthenticateToken(string, string?)
Authenticates the given token. If the token is valid, the related user is returned.
public User? AuthenticateToken(string token, string? prefix = null)
Parameters
Returns
DeleteOAuthClient(int)
Deletes an OAuth client token and its associated synthetic service-account user.
public bool DeleteOAuthClient(int id)
Parameters
idintThe id of the token to delete.
Returns
- bool
trueif both the token and user were deleted;falseotherwise.
GetToken(int)
Returns the Token with the given id.
public Token? GetToken(int id)
Parameters
idintThe id of the token to get.
Returns
- Token
The token matching the id if it exists;
nullotherwise.
GetToken(string, string?)
public static Token? GetToken(string token, string? prefix = null)
Parameters
Returns
GetTokens()
Returns a list of all Tokens.
public IEnumerable<Token> GetTokens()
Returns
- IEnumerable<Token>
List of all tokens.
RevokeToken(int)
Revokes the token with the given id.
public bool RevokeToken(int id)
Parameters
idintThe id of the token to revoke.
Returns
- bool
trueif the token was revoked;falseotherwise.
Save(Token)
Saves the given Token. This method cannot be used to create a new token.
public bool Save(Token token)
Parameters
tokenTokenThe token to save.
Returns
- bool
trueif the token was saved;falseotherwise.
Exceptions
- InvalidOperationException
If the given token doesn't already exist.
TryCreateOAuthClient(string, bool, string?, DateTime?)
Creates an OAuth 2.0 client_credentials client and a matching synthetic service-account user.
public static Token? TryCreateOAuthClient(string name, bool allowBackend, string? description = null, DateTime? expiryDate = null)
Parameters
namestringDisplay name of the client (required).
allowBackendboolWhether the backing service account may authenticate against backend APIs.
descriptionstringOptional description.
expiryDateDateTime?Optional expiry date for the client secret.
Returns
- Token
The newly created Token with PlaintextClientSecret populated. The secret is available only on this returned instance — it is never persisted. Returns
nullif creation failed.
TryCreateToken(ApiTokenRequestModel, User)
Tries to create a Token from the given ApiTokenRequestModel. If the data is valid and a token can be created, the unhashed token is returned. Once the token object has been saved, the unhashed token is lost and cannot be retrieved again.
public string? TryCreateToken(ApiTokenRequestModel tokenRequest, User user)
Parameters
tokenRequestApiTokenRequestModelThe request to create
userUserThe user that is creating the API Token.
Returns
- string
Unhashed token if creation was successful;
nullotherwise.
TryCreateToken(TokenRequestModel)
Tries to create a Token from the given TokenRequestModel. If the data is valid and a token can be created, the unhashed token is returned. Once the token object has been saved, the unhashed token is lost and cannot be retrieved again.
public string? TryCreateToken(TokenRequestModel tokenRequest)
Parameters
tokenRequestTokenRequestModelThe request to create
Returns
- string
Unhashed token if creation was successful;
nullotherwise.