Exemplo n.º 1
0
        /// <summary>
        /// Gets a list of users from the tenant. For demonstration purposes,
        /// the list of users is limited to 20 via OData filter.
        /// </summary>
        /// <param name="tenantId">string</param>
        /// <returns>Task<List<User>></returns>
        private async Task <List <User> > GetUsersAsync(string tenantId)
        {
            var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async(requestMessage) =>
            {
                string idToken = await this.HttpContext.GetTokenAsync("id_token").ConfigureAwait(false);

                var tg = new TokenGetter(
                    idToken,
                    string.Format(CultureInfo.InvariantCulture, AuthorityFormat, tenantId),
                    this.azureADOptions.ClientId,
                    this.azureADOptions.ClientSecret);

                var token = await tg.AcquireTokenOnBehalfOfAsync(MSGraphScope, this.HttpContext.User).ConfigureAwait(false);

                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                requestMessage.Headers.Add("Accept-Encoding", "*");
                requestMessage.Headers.Add("Accept", "text/*, application/*");
            }));

            List <QueryOption> options = new List <QueryOption>
            {
                new QueryOption("$top", "20"),
            };

            return((await graphServiceClient.Users.Request(options).GetAsync().ConfigureAwait(false)).ToList());
        }
Exemplo n.º 2
0
        public byte[] Serializer(NashaSettings settings, NashaInstruction instruction)
        {
            var buf = new byte[7];

            buf[0] = (byte)NashaOpcodes.Newobj.ShuffledID;
            var(referenceId, method) = (Tuple <short, IMethod>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(referenceId), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetMdToken(method)), 0, buf, 3, 4);
            return(buf);
        }
Exemplo n.º 3
0
        public byte[] Serialize(VMBody body, VMInstruction instruction, Offsets helper)
        {
            var buf = new byte[7];

            buf[0] = (byte)VMOpCode.Newarr;
            var(referenceid, type) = (Tuple <short, TypeDef>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(referenceid), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetMdToken(type)), 0, buf, 3, 4);
            return(buf);
        }
Exemplo n.º 4
0
        public byte[] Serializer(NashaSettings settings, NashaInstruction instruction)
        {
            var buf = new byte[7];

            buf[0] = (byte)NashaOpcode.Stsfld;
            var(referenceId, field) = (Tuple <short, IField>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(referenceId), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetFieldToken(field)), 0, buf, 3, 4);
            return(buf);
        }
Exemplo n.º 5
0
        public byte[] Serialize(VMBody body, VMInstruction instruction, Offsets helper)
        {
            var buf = new byte[7];

            buf[0]            = (byte)VMOpCode.Ldfld;
            var(refid, field) = (Tuple <short, FieldDef>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(refid), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetMdToken(field)), 0, buf, 3, 4);
            return(buf);
        }
Exemplo n.º 6
0
        public byte[] Serializer(NashaSettings settings, NashaInstruction instruction)
        {
            var buf = new byte[7];

            buf[0] = (byte)NashaOpcodes.Newarr.ShuffledID;
            var(referenceId, type) = (Tuple <short, ITypeDefOrRef>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(referenceId), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetTypeToken(type)), 0, buf, 3, 4);
            return(buf);
        }
Exemplo n.º 7
0
        public byte[] Serializer(NashaSettings settings, NashaInstruction instruction)
        {
            var buf = new byte[8];

            buf[0] = (byte)NashaOpcodes.Ldsfld.ShuffledID;

            var(referenceId, field, isGeneric) = (Tuple <short, IField, bool>)instruction.Operand;
            Array.Copy(BitConverter.GetBytes(isGeneric), 0, buf, 1, 1);
            Array.Copy(BitConverter.GetBytes(referenceId), 0, buf, 2, 2);
            Array.Copy(BitConverter.GetBytes(TokenGetter.GetFieldToken(field)), 0, buf, 4, 4);
            return(buf);
        }
        public TokenGetterTests()
        {
            this.channelFactoryWrapper.CreateFactory(TrustVersion.Default).ReturnsForAnyArgs(this.channelFactory);
            this.tokenGetter = new TokenGetter(this.channelFactoryWrapper);

            this.channel.Issue(Arg.Any <RequestSecurityToken>(), out this.requestSecurityTokenResponse).Returns(x =>
            {
                x[1] = new RequestSecurityTokenResponse();
                return(null);
            });
            this.channelFactory.CreateChannel(new EndpointAddress(UrnStsendpoint)).Returns(this.channel);
        }
Exemplo n.º 9
0
        public byte[] Serialize(VMBody body, VMInstruction instruction, Offsets helper)
        {
            var buf = new byte[8];

            buf[0] = (byte)VMOpCode.Call;
            var(referenceId, method) = (Tuple <short, MethodDef>)instruction.Operand;

            if (!body.Translated.ContainsKey(method))
            {
                Array.Copy(BitConverter.GetBytes(referenceId), 0, buf, 1, 2);
                Array.Copy(BitConverter.GetBytes(TokenGetter.GetMdToken(method)), 0, buf, 3, 4);
                buf[7] = 0;
                return(buf);
            }

            Array.Copy(BitConverter.GetBytes((short)body.MethodToIndex[method]), 0, buf, 1, 2);
            Array.Copy(BitConverter.GetBytes(method.Parameters.Count), 0, buf, 3, 4);
            buf[7] = 1;
            return(buf);
        }
Exemplo n.º 10
0
        //https://stackoverflow.com/questions/14104865/how-can-i-use-debug-write-with-dynamic-data
        public async Task <GetTokenResponseBase> GetTokenInfoAsyncByLocMai(string email, string password)
        {
            try
            {
                var response = await TokenGetter.RequestNew(email, password);

                string result = await response.Content.ReadAsStringAsync();

                dynamic resultJson = JsonConvert.DeserializeObject(result);

                string resultString = resultJson.ToString() as string;
                Debug.WriteLine(resultString);

                try
                {
                    var tokenInfo = new UserTokenInfo()
                    {
                        AccessToken = resultJson["access_token"].ToString() as string,
                        SessionKey  = resultJson["session_key"].ToString() as string,
                        Uid         = resultJson["uid"].ToString() as string,
                        Secret      = resultJson["secret"].ToString() as string,
                        Confirmed   = bool.Parse(resultJson["confirmed"].ToString() as string),
                        Identifier  = resultJson["identifier"].ToString() as string
                    };
                    return(new GetTokenResponseBase(tokenInfo));
                }
                catch (RuntimeBinderException)
                {
                    dynamic errorData = JsonConvert.DeserializeObject(resultJson["error_data"].ToString());
                    return(new GetTokenResponseBase(errorData["error_message"].ToString() as string));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(new GetTokenResponseBase($"An error occurred when creating new token: {ex.Message}"));
            }
        }
Exemplo n.º 11
0
        public ADFSWorkflow([NotNull] string stsEndpoint, [NotNull] TrustVersion trustVersion, [NotNull] TokenGetter tokenGetter, [NotNull] CookieGetter cookieGetter, string trustPath = "/_trust")
        {
            Assert.ArgumentNotNull(stsEndpoint, "stsEndpoint");
            Assert.ArgumentNotNull(trustVersion, "trustVersion");
            Assert.ArgumentNotNull(tokenGetter, "tokenGetter");
            Assert.ArgumentNotNull(cookieGetter, "cookieGetter");

            this.StsEndpoint  = stsEndpoint;
            this.TrustPath    = trustPath;
            this.TrustVersion = trustVersion;
            this.TokenGetter  = tokenGetter;
            this.CookieGetter = cookieGetter;
        }