public async static Task <bool> Authenticate() { bool hasAuthenticated = false; const string _authCodeString = "code"; // Build the URL where you can send the user to obtain an authorization code. var url = oAuthClient.GetAuthorizeUrl( "secretstate", Constants.callbackURL, new[] { Medium.Authentication.Scope.BasicProfile, Medium.Authentication.Scope.ListPublications, Medium.Authentication.Scope.PublishPost, }); url = url.Remove(url.LastIndexOf('&')); // (Send the user to the authorization URL to obtain an authorization code.) string result = await GetAuthCode(url); // Attempt to parse authorisation code from result // (Since result may not be a URL) try { Uri resultUri = new Uri(result); NameValueCollection queryDictionary = HttpUtility.ParseQueryString(resultUri.Query); string authCode = queryDictionary[_authCodeString]; Debug.WriteLine(authCode); //Exchange the authorization code for an access token. var accessToken = oAuthClient.GetAccessToken(authCode, Constants.callbackURL); TokenHelper.SaveTokenData(accessToken); hasAuthenticated = true; } catch (Exception) { } return(hasAuthenticated); }
public void GetAuthorizeUrl() { var client = new Medium.OAuthClient("clientId", "clientSecret"); var authorizeUrl = client.GetAuthorizeUrl("state", "uri", new[] { Medium.Authentication.Scope.BasicProfile, Medium.Authentication.Scope.PublishPost }); var expectedUrl = "https://medium.com/m/oauth/authorize?" + "client_id=clientId&" + "scope=basicProfile,publishPost&" + "state=state&" + "response_type=code&" + "redirect_uri=uri&"; Assert.Equal(expectedUrl, authorizeUrl); }