Пример #1
0
        // private helpers

        private AccessGrant ExchangeForAccess(bool expectParamBasedClientAuthentication, string responseFile)
        {
            OAuth2Template testedOAuth2Template = expectParamBasedClientAuthentication ? oAuth2TemplateParamBasedClientAuthentication : oAuth2Template;

            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_JSON;
            MockRestServiceServer mockServer     = MockRestServiceServer.CreateServer(testedOAuth2Template.RestTemplate);
            IRequestActions       requestActions = mockServer.ExpectNewRequest()
                                                   .AndExpectUri(ACCESS_TOKEN_URL)
                                                   .AndExpectMethod(HttpMethod.POST)
                                                   .AndExpectBody((expectParamBasedClientAuthentication ? "client_id=client_id&client_secret=client_secret&" : "") + "code=code&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fcallback&grant_type=authorization_code");

            if (!expectParamBasedClientAuthentication)
            {
                requestActions.AndExpectHeader("Authorization", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=");
            }
            requestActions.AndRespondWith(new AssemblyResource(responseFile, typeof(OAuth2TemplateTests)), responseHeaders);

#if NET_4_0 || SILVERLIGHT_5
            AccessGrant accessGrant = testedOAuth2Template.ExchangeForAccessAsync("code", "http://www.someclient.com/callback", null).Result;
#else
            AccessGrant accessGrant = testedOAuth2Template.ExchangeForAccess("code", "http://www.someclient.com/callback", null);
#endif
            return(accessGrant);
        }
Пример #2
0
        private AccessGrant AuthenticateClient(bool expectParamBasedClientAuthentication, string responseFile)
        {
            OAuth2Template testedOAuth2Template = expectParamBasedClientAuthentication ? oAuth2TemplateParamBasedClientAuthentication : oAuth2Template;

            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_JSON;
            MockRestServiceServer mockServer     = MockRestServiceServer.CreateServer(testedOAuth2Template.RestTemplate);
            IRequestActions       requestActions = mockServer.ExpectNewRequest()
                                                   .AndExpectUri(ACCESS_TOKEN_URL)
                                                   .AndExpectMethod(HttpMethod.POST)
                                                   .AndExpectBody((expectParamBasedClientAuthentication ? "client_id=client_id&client_secret=client_secret&" : "") + "grant_type=client_credentials&scope=read%2Cwrite");

            if (!expectParamBasedClientAuthentication)
            {
                requestActions.AndExpectHeader("Authorization", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=");
            }
            requestActions.AndRespondWith(new AssemblyResource(responseFile, typeof(OAuth2TemplateTests)), responseHeaders);

            OAuth2Parameters parameters = new OAuth2Parameters();

            parameters.Scope = "read,write";
#if NET_4_0 || SILVERLIGHT_5
            AccessGrant accessGrant = testedOAuth2Template.AuthenticateClientAsync("read,write").Result;
#else
            AccessGrant accessGrant = testedOAuth2Template.AuthenticateClient("read,write");
#endif
            return(accessGrant);
        }
 public void Setup()
 {
     oAuth2Template = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL);
 }
Пример #4
0
 public void Setup()
 {
     oAuth2Template = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL);
     oAuth2TemplateParamBasedClientAuthentication = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL, true);
 }
        public void Setup()
        {
		    oAuth2Template = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL);
            oAuth2TemplateParamBasedClientAuthentication = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL, true);
	    }