Servicestack LinkedIn Oauth2与Webauthenticator没有返回应用程序

时间:2016-10-14 22:26:55

标签: oauth-2.0 servicestack linkedin xamarin.auth

您好,我在使用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。

1 个答案:

答案 0 :(得分:2)

有一个示例项目,文档显示如何使用Xamarin.Auth验证ServiceStack: