Table of Contents

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

clientId string

The client ID (stored in cleartext).

clientSecret string

The plaintext client secret to validate.

Returns

User

The associated User if valid; null otherwise.

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

token string

The token to authenticate.

prefix string

Returns

User

The User related to the token if it's valid; null otherwise.

DeleteOAuthClient(int)

Deletes an OAuth client token and its associated synthetic service-account user.

public bool DeleteOAuthClient(int id)

Parameters

id int

The id of the token to delete.

Returns

bool

true if both the token and user were deleted; false otherwise.

GetToken(int)

Returns the Token with the given id.

public Token? GetToken(int id)

Parameters

id int

The id of the token to get.

Returns

Token

The token matching the id if it exists; null otherwise.

GetToken(string, string?)

public static Token? GetToken(string token, string? prefix = null)

Parameters

token string
prefix string

Returns

Token

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

id int

The id of the token to revoke.

Returns

bool

true if the token was revoked; false otherwise.

Save(Token)

Saves the given Token. This method cannot be used to create a new token.

public bool Save(Token token)

Parameters

token Token

The token to save.

Returns

bool

true if the token was saved; false otherwise.

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

name string

Display name of the client (required).

allowBackend bool

Whether the backing service account may authenticate against backend APIs.

description string

Optional description.

expiryDate DateTime?

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 null if 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

tokenRequest ApiTokenRequestModel

The request to create

user User

The user that is creating the API Token.

Returns

string

Unhashed token if creation was successful; null otherwise.

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

tokenRequest TokenRequestModel

The request to create

Returns

string

Unhashed token if creation was successful; null otherwise.

To top