Last active
April 16, 2022 23:53
-
-
Save jspinella/9f392bb94260fcde08cf0f4db9f8e14e to your computer and use it in GitHub Desktop.
ValueTuple Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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