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

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.

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.

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