我们可以为外部登录添加授权范围并将结果保存到 ServiceStack 中的数据库吗?
Can we add authorization scopes for external logins and save results to database in ServiceStack?
我们能否在 GoogleAuthProvider 中自定义范围以获取更多详细信息,例如他们的 phone 电话号码、地址或日历、个人资料图片?
我们还可以查看身份和访问令牌的详细信息并将这些结果解析并保存在我们的数据库中吗?
您可以在 GoogleAuthProvider.Scopes
集合中注册额外的范围,其中 by default is populated with:
this.Scopes = new[] {
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
};
来自所有 ServiceStack's OAuth Providers are populated in the registered Auth Repository in the UserAuthDetails table 的 OAuth 信息,其中访问令牌存储在 AccessTokenSecret
。
您可以使用访问令牌检索有关用户的其他信息,并在自定义 GoogleAuthProvider
中覆盖 CreateAuthInfo
并覆盖默认检索有关用户基本信息的 CreateAuthInfo()
实现来自 UserProfileUrl
(https://www.googleapis.com/oauth2/v2/userinfo):
protected override Dictionary<string, string> CreateAuthInfo(string accessToken)
{
var url = this.UserProfileUrl.AddQueryParam("access_token", accessToken);
var json = url.GetJsonFromUrl();
var obj = JsonObject.Parse(json);
obj.MoveKey("id", "user_id");
obj.MoveKey("given_name", "first_name");
obj.MoveKey("family_name", "last_name");
obj.MoveKey("picture", AuthMetadataProvider.ProfileUrlKey, profileUrl => profileUrl.SanitizeOAuthUrl());
return obj;
}
返回的字典填充了可覆盖 LoadUserAuthInfo() 中 UserAuthDetails
上的所有众所周知的属性(也可以用每个 AuthProvider 上的 LoadUserAuthFilter
拦截)。字典中所有其他不匹配的属性都保存在 UserAuthDetails
table.
上的 Items
字典中
我们能否在 GoogleAuthProvider 中自定义范围以获取更多详细信息,例如他们的 phone 电话号码、地址或日历、个人资料图片?
我们还可以查看身份和访问令牌的详细信息并将这些结果解析并保存在我们的数据库中吗?
您可以在 GoogleAuthProvider.Scopes
集合中注册额外的范围,其中 by default is populated with:
this.Scopes = new[] {
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
};
来自所有 ServiceStack's OAuth Providers are populated in the registered Auth Repository in the UserAuthDetails table 的 OAuth 信息,其中访问令牌存储在 AccessTokenSecret
。
您可以使用访问令牌检索有关用户的其他信息,并在自定义 GoogleAuthProvider
中覆盖 CreateAuthInfo
并覆盖默认检索有关用户基本信息的 CreateAuthInfo()
实现来自 UserProfileUrl
(https://www.googleapis.com/oauth2/v2/userinfo):
protected override Dictionary<string, string> CreateAuthInfo(string accessToken)
{
var url = this.UserProfileUrl.AddQueryParam("access_token", accessToken);
var json = url.GetJsonFromUrl();
var obj = JsonObject.Parse(json);
obj.MoveKey("id", "user_id");
obj.MoveKey("given_name", "first_name");
obj.MoveKey("family_name", "last_name");
obj.MoveKey("picture", AuthMetadataProvider.ProfileUrlKey, profileUrl => profileUrl.SanitizeOAuthUrl());
return obj;
}
返回的字典填充了可覆盖 LoadUserAuthInfo() 中 UserAuthDetails
上的所有众所周知的属性(也可以用每个 AuthProvider 上的 LoadUserAuthFilter
拦截)。字典中所有其他不匹配的属性都保存在 UserAuthDetails
table.
Items
字典中