2
2
3
3
using System ;
4
4
using System . Globalization ;
5
- using System . Linq ;
6
5
using System . Security . Claims ;
7
6
using Microsoft . Owin ;
8
7
using Microsoft . Owin . Security ;
@@ -20,16 +19,14 @@ public class GoogleAuthenticatedContext : BaseContext
20
19
/// Initializes a <see cref="GoogleAuthenticatedContext"/>
21
20
/// </summary>
22
21
/// <param name="context">The OWIN environment</param>
23
- /// <param name="user">The JSON-serialized user</param>
24
- /// <param name="person"></param>
25
- /// <param name="accessToken">Google+ Access token</param>
22
+ /// <param name="userInfo">The JSON-serialized user_info. Format described here: https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims</param>
23
+ /// <param name="accessToken">Google Access token</param>
26
24
/// <param name="expires">Seconds until expiration</param>
27
25
/// <param name="refreshToken"></param>
28
- public GoogleAuthenticatedContext ( IOwinContext context , JObject user , JObject person , string accessToken , string expires , string refreshToken )
26
+ public GoogleAuthenticatedContext ( IOwinContext context , JObject userInfo , string accessToken , string expires , string refreshToken )
29
27
: base ( context )
30
28
{
31
- User = user ;
32
- Person = person ;
29
+ UserInfo = userInfo ;
33
30
AccessToken = accessToken ;
34
31
RefreshToken = refreshToken ;
35
32
@@ -39,16 +36,15 @@ public GoogleAuthenticatedContext(IOwinContext context, JObject user, JObject pe
39
36
ExpiresIn = TimeSpan . FromSeconds ( expiresValue ) ;
40
37
}
41
38
42
- Id = TryGetValue ( person , "id" ) ;
43
- Name = TryGetValue ( person , "displayName" ) ;
44
- Link = TryGetValue ( person , "url" ) ;
45
- UserName = TryGetValue ( person , "displayName" ) . Replace ( " " , "" ) ;
39
+ // See https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims for a list of properties
40
+ Id = TryGetValue ( userInfo , "sub" ) ;
41
+ Name = TryGetValue ( userInfo , "name" ) ;
42
+ Link = TryGetValue ( userInfo , "profile" ) ;
43
+ UserName = TryGetValue ( userInfo , "name" ) . Replace ( " " , "" ) ;
46
44
47
- var email = ( from e in person [ "emails" ]
48
- where e [ "type" ] . ToString ( ) == "account"
49
- select e ) . FirstOrDefault ( ) ;
45
+ var email = TryGetValue ( userInfo , "email" ) ;
50
46
if ( email != null )
51
- Email = email [ "value" ] . ToString ( ) ;
47
+ Email = email ;
52
48
}
53
49
54
50
/// <summary>
@@ -57,16 +53,7 @@ public GoogleAuthenticatedContext(IOwinContext context, JObject user, JObject pe
57
53
/// <remarks>
58
54
/// Contains the Google user obtained from the endpoint https://www.googleapis.com/oauth2/v3/userinfo
59
55
/// </remarks>
60
- public JObject User { get ; private set ; }
61
-
62
- /// <summary>
63
- /// Gets the JSON-serialized person
64
- /// </summary>
65
- /// <remarks>
66
- /// Contains the Google+ person obtained from the endpoint https://www.googleapis.com/plus/v1/people/me. For more information
67
- /// see https://developers.google.com/+/api/latest/people
68
- /// </remarks>
69
- public JObject Person { get ; private set ; }
56
+ public JObject UserInfo { get ; private set ; }
70
57
71
58
/// <summary>
72
59
/// Gets the Google OAuth access token
@@ -79,12 +66,12 @@ public GoogleAuthenticatedContext(IOwinContext context, JObject user, JObject pe
79
66
public string RefreshToken { get ; private set ; }
80
67
81
68
/// <summary>
82
- /// Gets the Google+ access token expiration time
69
+ /// Gets the Google access token expiration time
83
70
/// </summary>
84
71
public TimeSpan ? ExpiresIn { get ; set ; }
85
72
86
73
/// <summary>
87
- /// Gets the Google+ user ID
74
+ /// Gets the Google user ID
88
75
/// </summary>
89
76
public string Id { get ; private set ; }
90
77
@@ -96,12 +83,12 @@ public GoogleAuthenticatedContext(IOwinContext context, JObject user, JObject pe
96
83
public string Link { get ; private set ; }
97
84
98
85
/// <summary>
99
- /// Gets the Google+ username
86
+ /// Gets the Google username
100
87
/// </summary>
101
88
public string UserName { get ; private set ; }
102
89
103
90
/// <summary>
104
- /// Gets the Google+ email address for the account
91
+ /// Gets the Google email address for the account
105
92
/// </summary>
106
93
public string Email { get ; private set ; }
107
94
0 commit comments