using spring RestTemplate and 2 factor authenication to add issues to github

Last month, I figured out how to use Spring’s RestTemplate to add issues to github programmatically figuring it would save me time in the future.  Well, the future is here.  I needed to add 16 issues (one per milestone.)  I run my program and get a 401.  In particular, I got

Apr 20, 2014 6:42:18 PM org.springframework.web.client.RestTemplate handleResponseError

WARNING: GET request for "https://api.github.com/repos/boyarsky/repoName/issues" resulted in 401 (Unauthorized); invoking error handler

Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 401 Unauthorized

at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)

at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:588)

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:546)

at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:502)

at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:444)

at jb.Trial2.main(Trial2.java:29)

Right.  I’ve changed my password AND enabled two factor authentication on github in the past month.  Luckily, it was easy to switch my program to two factor.  Here’s what I did.

Create personal use token

I created a second personal use token just like I did for for my git commmand line use by going to the applications page and clicking “generate new token”.  I chose to create a separate token so I could revoke access as soon as I’m done running the web service.

Testing the token

Per the getting started with oauth doc, I ran a command line to test the token:

curl -i -H 'Authorization: token notMy40CharToken' \

https://api.github.com/user

 Wrote another trial program

I adapted my second trial program from the initial iterations to test out two factor.

package jb;

import org.springframework.http.*;
import org.springframework.web.client.*;

/**
 * Call a web service that uses authenticated user to test passing credentials
 *
 * @author jeanne
 *
 */
public class Trial3 {

	public static void main(String[] args) {
		String url = "https://api.github.com/repos/boyarsky/oca-ocp-book/issues";

		HttpHeaders headers = new HttpHeaders();

		String personalToken = "notMy40CharToken";
		headers.add("Authorization", "token " + personalToken);

		// ignore result because just testing connectivity
		HttpEntity<String> request = new HttpEntity<String>(headers);
		RestTemplate template = new RestTemplate();
		template.exchange(url, HttpMethod.GET, request, Object[].class);
		System.out.println("success");
	}

}

I then replaced the authentication part of my real program and it worked like a charm.  Even with the changes to the program, it was faster than creating 16 issues by hand with the proper text/assignee/milestone.

Delete the personal token

I deleted the token to ensure it never gets used again.  I don’t want to run the program by accident with my credentials.  Or accidentally post the token here.

2-factor authentication and twitter

I’ve had two factor for gmail enabled for two years.  This morning, I set up two factor for github and some others due to Heartbleed (check if sites you use are affected), Then there was Twitter.  After the other sites being straightforward, I expected the same from Twitter.  Twitter did not deliver.  I had to turn off two factor.  I’m left with secure my password and hope I notice if someone logs into my account.  (I think my friends would tell me about bad direct messages)

How to enable on a mobile device

  1. Install the official twitter app on my iPad
  2. Follow the menus described here
  3. Write down the backup code
  4. I logged off in a browser and re-logged in.
  5. Then I went to the twitter app and approved my login under settings.

And if it ended here, all would be fine.

Adding a phone number

I thought about adding a phone number as another option.  Don’t bother.  They are mutually exclusive.

Apparently they are mutually exclusive.  I cancelled the phone number sign up process part way through due to usability issues.  (Twitter wants you to text GO to 40404.  I don’t know how to do that on my BlackBerry.  I know how to reply to texts and text real numbers.  And I don’t want to lookup how to do it since I likely never will again.)

Anyway, when I clicked cancel on the process, it had already turned off my iPad option so I had to set it up again.  Grumble.

The BlackBerry app

Once I had two factor turned on, I was no longer able to logon to Twitter using the BlackBerry app.  A quick search online says I’m not the only one with this problem and the BlackBerry app just plain doesn’t support it.  Which means I can’t use two factor for Twitter.

enabling more two factor – paypal, dropbox, linked in and yahoo

I’ve had two factor for gmail enabled for two years.  This morning, I set up two factor for github.  Due to Heartbleed (check if sites you use are affected), I checked who else permits two factor to revisit what I should turn on.  Twitter has it’s own post because it didn’t go smoothly like the others did.

I had originally decided not to turn on two factor for sites that don’t provide an app as I prefer not to get texts.  However, I notice they only text you when you log in from a new device.  And I get enough junk texts by now that this is a rounding error.

Paypal

I have a paypal account but hardly use it.  It was so secure that I didn’t even know my main password.

  1. Go to this page.
  2. Choose the option to use a mobile number (vs a $30 device)
  3. Enter your phone number
  4. Enter the code sent via a text to prove you control that phone number.  Do so quickly.  The code expires in 5 minutes.

Dropbox

Dropbox was similar to github.  It uses Google Authenticator plus a backup phone code and backup text string.  The only annoyance was that I had trouble scanning the QR code.  I had to drag the browser to my second screen (which is larger so has better resolution.)

Dropbox didn’t make me re-connect my existing sessions.  I left them alone because I don’t want to sync all that data again.  Presumably two factor will protect me against anyone else using my login.

Linked in

  1. Go to the security page,
  2. Click Turn on for two factor
  3. Enter your phone number
  4. Enter the code sent via a text to prove you control that phone number

Yahoo mail

I hadn’t secured yahoo because I use it as my “backup” email provider.  Why not though.

  1. Go to this page.
  2. Enter your phone numbe
  3. Enter the “six digit” code sent via a text to prove you control that phone number.  (My “six digit” code was five digits.  I guess they are counting invisible leading zeros)