Hey @aorsten,
Currently not possible, but…
at this point we do not have a CurrentToken() kind of function so there is no way to do that.
… it’s already in our backlog, and …
I have pondered about the same thing and actually also asked to implement something like that. There were already ideas on the table, I’ll add your request to the ticket. I was also tempted to add data on my token (since it’s also document anyway) and use that in my ABAC roles or UDF functionality. Being able to do that would be great.
… there is a workaround
That said, it’s definitely not impossible to have something similar but it’s a bit cumbersome.
You can make a collection ‘tokens’ instead and make sure that if you create a new token, you always first create a new document and then create a token for that document.
In my use case, I wanted to have a difference between ‘refresh’ and ‘access’ tokens and hoped to put a type on the token. Instead I implemented a ‘session’ collection on which I create a document and a token when I want to retrieve a refresh token.
function CreateRefreshToken(accountRef) {
return Let(
{
session_refresh: Create(Collection('account_sessions'), {
data: {
account: accountRef,
used: false
}
})
},
{
token: Create(Tokens(), {
instance: Select(['ref'], Var('session_refresh')),
// 8 hours is a good time for refresh tokens.
ttl: TimeAdd(Now(), 8, 'hour'),
data: {
// We do not do anything with the type, it's just for readability in case we retrieve a token later on
type: 'refresh'
}
}),
session_refresh_doc: Var('session_refresh')
}
)
}
As you can see, this document refers to the ‘account’ which is the actual identity that I will authenticate. Of course, this makes your roles slightly more complex since you have to follow that indirection. My Identity() will be the session document and I’ll get the account via a Get. It’s probably clearer when I show you how an account_session looks like:
Refresh tokens in my case are created on the account_sessions and in my roles/UDFs I follow the account ref of that session back to the account.
Access tokens are created on accounts.
I know this is a cumbersome workaround, as I mentioned, I asked this feature myself and will add your request to the ticket . I do hope this helps already in the meantime