コード例 #1
0
        public async System.Threading.Tasks.Task <HttpResponseMessage> Authorize(string userid, string code)
        {
            AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize/");
            ClientCredential      cc = new ClientCredential(Constants.Constants.ADClientId, Constants.Constants.ADClientSecret);
            AuthenticationResult  ar = await ac.AcquireTokenByAuthorizationCodeAsync(code, new Uri(Constants.Constants.apiBasePath + userid + "/authorize"), cc);

            if (!String.IsNullOrEmpty(ar.AccessToken))
            {
                //StateClient stateClient = new StateClient(new Uri("https://state.botframework.com/"));
                StateClient stateClient = new StateClient(new Uri("http://localhost:9000/"));

                if (stateClient != null)
                {
                    var getData = await stateClient.BotState.GetUserDataAsync(Constants.Constants.botId, userid);

                    //var getData = await client.B.GetUserDataAsync(Constants.Constants.botId, userid);
                    getData.Data = ar.Serialize();
                    var foo = await stateClient.BotState.SetUserDataAsync(Constants.Constants.botId, userid, getData);

                    //var foo = await client.Bots.SetUserDataAsync(Constants.Constants.botId, userid, getData);
                }
                //return Request.CreateResponse(foo);
                var response = Request.CreateResponse(HttpStatusCode.Moved);
                response.Headers.Location = new Uri("/loggedin.html", UriKind.Relative);
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
コード例 #2
0
        public string AcquireToken(string resrouceUrl)
        {
            string token;

            if (TryAcquireToken(out token))
            {
                return(token);
            }

            var redirectUri = new Uri(Settings.RedirectUri);

            AuthenticationContext authenticationContext = new AuthenticationContext(Settings.AuthString, false);

            AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resrouceUrl,
                                                                                           Settings.ClientIdForUserAuth, redirectUri, PromptBehavior.Always);

            File.WriteAllText(TOKEN_CACHE_FIIE, authenticationResult.Serialize());

            token = authenticationResult.AccessToken;

            return(token);
        }
コード例 #3
0
ファイル: TokenUtils.cs プロジェクト: suwatch/CSMClient
 public static void SaveRecentToken(AuthenticationResult authResult)
 {
     ProtectedFile.WriteAllText(GetRecentTokenFile(), authResult.Serialize());
 }