public static AuthToken Parse(string text, bool isRgx = false) { AuthToken token = null; if (isRgx) { var matchAccessToken = rgxAccessToken.Match(text); var matchRefreshToken = rgxRefreshToken.Match(text); var matchTokenType = rgxTokenType.Match(text); var matchExpiresIn = rgxExpiresIn.Match(text); if (matchAccessToken.Success && matchRefreshToken.Success) { token = new AuthToken(); token.access_token = matchAccessToken.Groups[1].Value; token.refresh_token = matchRefreshToken.Groups[1].Value; token.token_type = matchTokenType.Groups[1].Value; token.expires_in = Convert.ToInt32(matchExpiresIn.Groups[1].Value); } else return null; } else { token = SerializeExtension.JsonDeserlialize<AuthToken>(text); } token.ExpiresIn = DateTime.Now.AddSeconds(token.expires_in); return token; }
public void SetToken(AuthToken token) { Token = token; }