Add VSO Refresh Token
This commit is contained in:
@@ -19,11 +19,13 @@ namespace Owin.Security.Providers.VisualStudio {
|
||||
/// <param name="context">The OWIN environment</param>
|
||||
/// <param name="user">The JSON-serialized user</param>
|
||||
/// <param name="accessToken">Visual Studio Online Access token</param>
|
||||
public VisualStudioAuthenticatedContext(IOwinContext context, JObject user, string accessToken)
|
||||
public VisualStudioAuthenticatedContext(IOwinContext context, JObject user, string accessToken, int expiresIn, string refreshToken)
|
||||
: base(context)
|
||||
{
|
||||
AccessToken = accessToken;
|
||||
User = user;
|
||||
RefreshToken = refreshToken;
|
||||
ExpiresIn = TimeSpan.FromSeconds(expiresIn);
|
||||
|
||||
Id = TryGetValue(user, "id");
|
||||
Name = TryGetValue(user, "displayName");
|
||||
@@ -44,6 +46,16 @@ namespace Owin.Security.Providers.VisualStudio {
|
||||
/// </summary>
|
||||
public string AccessToken { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Google OAuth refresh token. This is only available when the RequestOfflineAccess property of <see cref="GooglePlusAuthenticationOptions"/> is set to true
|
||||
/// </summary>
|
||||
public string RefreshToken { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Google+ access token expiration time
|
||||
/// </summary>
|
||||
public TimeSpan? ExpiresIn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the user's id
|
||||
/// </summary>
|
||||
|
||||
@@ -73,6 +73,8 @@ namespace Owin.Security.Providers.VisualStudio {
|
||||
// Deserializes the token response
|
||||
dynamic response = JsonConvert.DeserializeObject<dynamic>(text);
|
||||
string accessToken = (string)response.access_token;
|
||||
string refreshToken = (string)response.refresh_token;
|
||||
int expiresIn = (int)response.expires_in;
|
||||
|
||||
// Get the Visual Studio Online user
|
||||
HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, Options.Endpoints.UserInfoEndpoint);
|
||||
@@ -83,7 +85,7 @@ namespace Owin.Security.Providers.VisualStudio {
|
||||
text = await userResponse.Content.ReadAsStringAsync();
|
||||
JObject user = JObject.Parse(text);
|
||||
|
||||
var context = new VisualStudioAuthenticatedContext(Context, user, accessToken);
|
||||
var context = new VisualStudioAuthenticatedContext(Context, user, accessToken, expiresIn, refreshToken);
|
||||
context.Identity = new ClaimsIdentity(
|
||||
Options.AuthenticationType,
|
||||
ClaimsIdentity.DefaultNameClaimType,
|
||||
|
||||
Reference in New Issue
Block a user