Skip to content

Commit

Permalink
Cleaned up Auth Service
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed May 5, 2012
1 parent 6cea825 commit 333c7a6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ReviewR.Web/Services/AuthenticationService.cs
Expand Up @@ -39,11 +39,7 @@ public virtual User GetUserByEmail(string email)

public async virtual Task<UserInfo> ResolveAuthTokenAsync(string authenticationToken)
{
HttpClient client = new HttpClient();
HttpResponseMessage resp = await client.GetAsync(String.Format(
"https://rpxnow.com/api/v2/auth_info?apiKey={0}&token={1}",
Settings.Get("Janrain:ApiKey"),
authenticationToken), HttpCompletionOption.ResponseContentRead);
HttpResponseMessage resp = await ExchangeToken(authenticationToken);

if (!resp.IsSuccessStatusCode)
{
Expand All @@ -64,6 +60,12 @@ public async virtual Task<UserInfo> ResolveAuthTokenAsync(string authenticationT
verifiedEmail = ""
}
});

if (identifier == null || identifier.profile == null)
{
return null;
}

string name = identifier.profile.displayName;
if (identifier.profile.name != null && !String.IsNullOrEmpty(identifier.profile.name.formatted))
{
Expand Down Expand Up @@ -120,5 +122,14 @@ public virtual void AddCredential(int userId, string provider, string identifier
});
Data.SaveChanges();
}

protected internal async virtual Task<HttpResponseMessage> ExchangeToken(string token)
{
HttpClient client = new HttpClient();
return await client.GetAsync(String.Format(
"https://rpxnow.com/api/v2/auth_info?apiKey={0}&token={1}",
Settings.Get("Janrain:ApiKey"),
token), HttpCompletionOption.ResponseContentRead);
}
}
}

0 comments on commit 333c7a6

Please sign in to comment.