Skip to content

Instantly share code, notes, and snippets.

@jspinella
Last active April 16, 2022 23:53
Show Gist options
  • Save jspinella/9f392bb94260fcde08cf0f4db9f8e14e to your computer and use it in GitHub Desktop.
Save jspinella/9f392bb94260fcde08cf0f4db9f8e14e to your computer and use it in GitHub Desktop.
ValueTuple Example
public async Task<(string token, DateTime expirationDate)> GetToken(User user) // syntactic sugar for the ValueTuple type
{
var response = await "https://api.website.com/oauth2/token/" // I'm taking some liberties here, this is not totally legit auth code, but it would utlize properties from the User object passed into the method
.ReceiveJson<TokenResponse>();
var token = response.access_token.ToString();
var expirationDate = DateTime.Now.AddSeconds(response.expires_in);
return (token, expirationDate); // can also express ValueTuple explicitly: return new ValueTuple<string, DateTime>(token, expirationDate);
}
public async Task<string> GetBearerToken(User user)
{
var (token, expirationDate) = await _securityRepository.GetToken(user);
UpdateBearerToken(user.Username, token, expirationDate);
return tokenResult.token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment