Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin.Auth - Get Authorization Code and Get Access Token

DiamondKeshaDiamondKesha Member ✭✭

How i can get access token?
Api shikimori -
Get Authorization Code -
Get Access Token - curl -X POST "" \ -H "User-Agent: APPLICATION_NAME" \ -F grant_type="authorization_code" \ -F client_id="CLIENT_ID" \ -F client_secret="CLIENT_SECRET" \ -F code="AUTORIZATION_CODE" \ -F redirect_uri="REDIRECT_URI"

and my code in app -
private void LogInShikimori(object sender, EventArgs e)

            var auth = new OAuth2Authenticator(
                clientId: "Mgjmzju3RuU2TyuGktAJIx5yHEV5K9QY2VFv-gJumww",
                scope: "user_rates",
                authorizeUrl: new Uri(""),
                redirectUrl: new Uri("urn:ietf:wg:oauth:2.0:oob"),
                clientSecret: "code",
                accessTokenUrl: new Uri("")
            auth.AllowCancel = true;
            auth.Completed += OnAuthCompleted;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
            if (e.IsAuthenticated)
                String requestContent = $"grant_type=authorization_code&client_id=Mgjmzju3RuU2TyuGktAJIx5yHEV5K9QY2VFv-gJumww&client_secret=w9LT2Nj_EClfY1wVzZ5nPm8rGKCwM$code={e.Account.Properties["access_token"]}&redirect_uri=urn: ietf: wg: oauth: 2.0:oob";
                var Request = (HttpWebRequest)WebRequest.Create("");
                Request.UserAgent = "🔎 Search Anime";
                Request.Method = "POST";
                Request.ContentType = "application/x-www-form-urlencoded";

                byte[] bytes = System.Text.Encoding.ASCII.GetBytes(requestContent);
                Request.ContentLength = bytes.Length;
                using (System.IO.Stream outputStream = Request.GetRequestStream())
                    outputStream.Write(bytes, 0, bytes.Length);
                WebResponse webResponse = Request.GetResponse();

                DisplayAlert(null, webResponse.ToString(), null);

What am I doing wrong? Help me please

Sign In or Register to comment.