コード例 #1
0
        public async Task <string> Get(
            bool ccaPerRequest = true,
            Flow flow          = Flow.S2S,
            int userForObo     = 1,
            TID tenantId       = TID.A,
            Scope scope        = Scope.S1,
            bool staticL1      = false,
            bool useL2         = true)
        {
            char c   = tenantId.ToString().ToCharArray()[0];
            var  tid = new string(Enumerable.Repeat(c, 16).ToArray());

            IConfidentialClientApplication cca = GetOrCreateCCA(ccaPerRequest, staticL1, useL2);

            AuthenticationResult res;

            if (flow == Flow.S2S)
            {
                res = await cca.AcquireTokenForClient(new[] { scope.ToString() })
                      .WithAuthority($"https://login.microsoftonline.com/{tid}")
                      .ExecuteAsync().ConfigureAwait(false);
            }
            else
            {
                var user = $"user_{userForObo}";

                // must be in this format. MSAL will use {user} as the object id
                string fakeUpstreamToken = $"upstream_token_{user}";

                res = await cca.AcquireTokenOnBehalfOf(new[] { scope.ToString() }, new UserAssertion(fakeUpstreamToken))
                      .WithAuthority($"https://login.microsoftonline.com/{tid}")
                      .ExecuteAsync()
                      .ConfigureAwait(false);
            }



            return(res.AuthenticationResultMetadata.TokenSource.ToString());
        }
コード例 #2
0
        void Reader_TagInventoryEvent(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            // Check Callback Type
            if (e.type != CSLibrary.Constants.CallbackType.TAG_RANGING)
            {
                return;
            }

            UInt32 TID, TID1;
            string EPC;

            UInt16[] tagdata = e.info.epc.ToUshorts();

            // Check TID code (exclude if scan temp)
            //TID = (UInt32)((tagdata[e.info.pc.EPCLength] << 16) | tagdata[e.info.pc.EPCLength + 1]) & 0xffffffc0U;
            //if (TID != 0xe2806e80U && TID != 0xe2806e8fU && TID != 0xe2806800U)
            //    return;

            TID  = (UInt32)((tagdata[e.info.pc.EPCLength] << 16) | tagdata[e.info.pc.EPCLength + 1]);
            TID1 = TID & 0xffffffc0U;
            if (TID1 != 0xe2806e80U && TID1 != 0xe2806e8fU && TID1 != 0xe2806800U)
            {
                return;
            }

            EPC = e.info.epc.ToString().Substring(0, (int)(e.info.pc.EPCLength * 4)) + ":" + TID.ToString("X8");

            BeginInvoke((System.Threading.ThreadStart) delegate()
            {
                lock (listView1)
                {
                    int cnt;

                    for (cnt = 0; cnt < listView1.Items.Count; cnt++)
                    {
                        if (listView1.Items[cnt].SubItems[1].Text == EPC)
                        {
                            break;
                        }
                    }

                    if (cnt == listView1.Items.Count)
                    {
                        ListViewItem ins = new ListViewItem((listView1.Items.Count + 1).ToString());
                        ins.SubItems.Add(EPC);

                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0800) != 0x0000)
                        {
                            ins.SubItems.Add("1");
                        }
                        else
                        {
                            ins.SubItems.Add("0");
                        }

                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0040) != 0x0000)
                        {
                            ins.SubItems.Add("1");
                        }
                        else
                        {
                            ins.SubItems.Add("0");
                        }

                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0001) != 0x0000)
                        {
                            ins.SubItems.Add("1");
                        }
                        else
                        {
                            ins.SubItems.Add("0");
                        }

                        listView1.Items.Add(ins);
                    }
                    else
                    {
                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0800) != 0x0000)
                        {
                            listView1.Items[cnt].SubItems[2].Text = "1";
                        }
                        else
                        {
                            listView1.Items[cnt].SubItems[2].Text = "0";
                        }

                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0040) != 0x0000)
                        {
                            listView1.Items[cnt].SubItems[3].Text = "1";
                        }
                        else
                        {
                            listView1.Items[cnt].SubItems[3].Text = "0";
                        }

                        if ((tagdata[e.info.pc.EPCLength + 2] & 0x0001) != 0x0000)
                        {
                            listView1.Items[cnt].SubItems[4].Text = "1";
                        }
                        else
                        {
                            listView1.Items[cnt].SubItems[4].Text = "0";
                        }
                    }
                }
            });
        }