Friday, July 11, 2014

Changing Releases and Tags on GitHub to a Different Commit

I recently came across a situation where I accidentally created a release on GitHub, pointed at a specific tag which was tagged to a commit. I fixed the changes, committed, but wanted the release to point to the new commit instead of the old one with the error. Unfortunately, GitHub doesn't have a way to do this online, but it can be done through a combination of command line git and the GitHub website.

First, make sure your repo is up-to-date with "git fetch." This will pull down the tag you made, including the wrong one.

git fetch

Next, delete the old tag by running:

git tag -d [tag-name-here]

So, for example, I did:

git tag -d v1.1.0

Next, commit and push your latest changes including the change you want the release to point to:

git add folder/file
git commit -m "message here"
git push -u origin master

Finally, push your tag changes as well:

git push origin :[tag-name-here]

If your tag has the same name as a branch, run:

git push origin :refs/tags/[tag-name-here]

Now, open GitHub in your browser and navigate to the "releases" page. Your release should now be listed as a "Draft" because its tag has been deleted.

You can now discard this release and create a new one with the same name pointed at the most recent commit.

Wednesday, July 2, 2014

Use google-passport Authentication in Node.js Projects without Google+

NPM passport-google and 400 Error "OpenID auth request contains an unregistered domain"

If you've been using the Node.js module "passport-google" for authentication in your projects you will now notice that new projects are receiving an error stating:

"400 That's an error. OpenID auth request contains an unregistered domain."

This issue is due to the fact that Google has deprecated their OpenID API for new domains beginning in May 2014. Old projects which had previously been used should not have an issue (although you should upgrade at some point), but new projects will not be allowed to authenticate.

There are two fixes for this:

1) Convert your application to using the new, Google+ sign-in. This will require users to have a Google+ profile and approve your application to access it. The passport-google-plus module located on GitHub can do just that: https://github.com/sqrrrl/passport-google-plus

2) Convert your application to use OAuth2.0 signin. Your users will not need to have a Google+ profile and this new method is the closest match to the old. The passport-google-oauth module can help with this: https://github.com/jaredhanson/passport-google-oauth

If you choose the second option, be sure to only provide the userinfo scope (and not the google.plus scope):

passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.email'] })

One additional note is that you will now be required to register your application at https://console.developers.google.com and create a client ID and secret (which are used in the passport module).