【问题标题】:Servicestack LinkedIn Oauth2 with Webauthenticator Not Returning to App带有 Webauthenticator 的 Servicestack LinkedIn Oauth2 未返回到应用程序
【发布时间】:2016-11-26 04:22:47
【问题描述】:

您好,我在使用 Xamarin.auth 组件进行 Servicestack 身份验证时遇到问题。

当尝试使用 WebAuthencator 使用 ServiceStack 进行身份验证时,我正在通过身份验证但无法返回应用程序,就像仅在 Xamarin.Auth 的情况下一样。

[Route("/my-session")]
public class CustomUserSession : AuthUserSession ,IReturn<CustomUserSession>
{
    public string GithubProfileUrl { get; set; }
    public string TwitterProfileUrl { get; set; }
    IRedisClientsManager RedisManager;


    public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
    {
        base.OnAuthenticated(authService, session, tokens, authInfo);
        var userAuthRepo = authService.ResolveService<IUserAuthRepository>();
        var userAuth = userAuthRepo.GetUserAuth(session.UserAuthId);
}

}

这是来自 JsonServiceClient 的 RAW 请求

GET http://sample.com/api/my_info HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Authorization: DotNetOpenAuth.WebServerClient.XSRF-Session=GGcwh7UvAe3R5ivrrAv7MQ; ss-id=5byYKQ5TYwmYqK3EQ5Vi; ss-pid=82ZTomRsZmdRTTA6dkMF; X-UAId=1
Connection: keep-alive
Host: sample.com

RESPONSE :
HTTP/1.1 401 Unauthorized
Cache-Control: private
Server: Microsoft-IIS/8.5
WWW-Authenticate: LinkedIn realm="https://www.linkedin.com/uas/oauth2/authorization"
X-Powered-By: ServiceStack/4.0 Win32NT/.NET
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 25 Nov 2016 19:59:37 GMT
Content-Length: 0

而在浏览器中对 /api/my_info 的相同调用会重定向到 auth 并获取信息。

浏览器请求:

GET /api/my_info HTTP/1.1
Host: sample.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: ss-pid=pnxqAEU3ExIzrVZ8QdR/; ss-id=qCAkeAUDbQ+QRkZvIQgv; DotNetOpenAuth.WebServerClient.XSRF-Session=lFqnWxGQfdOZEF55MrLT_Q; X-UAId=1

浏览器响应:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/8.5
X-Powered-By: ServiceStack Win32NT/.NET
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 22 Nov 2016 20:38:37 GMT
Content-Length: 9443
Connection: keep-alive

<!doctype html>
<html lang="en-us">
<head>
<title>Simple Snapshot of 11/22/2016</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
BODY, H1, H2, H3, H4, H5, H6, DL, DT, DD {
..............

JsonServiceClient 也获得了 ss-id,但后来调用身份验证服务失败并出现 401。

【问题讨论】:

    标签: oauth-2.0 servicestack linkedin xamarin.auth


    【解决方案1】:

    有一个示例项目的文档展示了如何使用 Xamarin.Auth 对 ServiceStack 进行身份验证,请访问:

    【讨论】:

    • 我遵循了相同的解决方案,但卡在 LinkedIn 上提供的 redirectUri。
    • 这里有问题
    • @TechCruize A NotFound 异常意味着您尝试调用的服务不存在。该演示使用它作为在您通过身份验证后调用 Authenticated Service 的示例,对于 TechStacks 示例,它调用此 Custom Service which returns the Authenticated Users Session
    • @TechCruize 就像任何其他服务一样,它仍然只是返回一个填充的 DTO。您能否发布原始 HTTP 标头,这是了解发生了什么的最佳方式。
    • @TechCruize 如果添加[Authenticate] 导致错误,则表明您没有经过身份验证的客户端。 [Authenticate] 属性的目的是确保只有经过身份验证的用户才能访问该服务 - 错误表示请求未经过身份验证。就像我在上面反复要求的那样,我们需要查看身份验证请求 + 失败的服务请求的原始 HTTP 请求/响应标头,以便了解实际发生的情况。
    猜你喜欢
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    相关资源
    最近更新 更多