Skip to content

user454322/browserid-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrowserID Verifier Build Status

BrowserID Verifier is a simple verifier for the BrowserID protocol but, it has been tested only with Mozilla Persona.

The only external dependencies are SLF4J and json.org.

To use it, just write something like:

BrowserIDResponse loginRepsonse = verifier.verify(assertion, AUDIENCE);

Find a simple, yet complete live sample here with its source code.

How to use it

1. Add it as a dependency

Its Maven coordinate is info.modprobe:browserid-verifier:<version> in a pom file it would look like:

   <dependency>
      <groupId>info.modprobe</groupId>
      <artifactId>browserid-verifier</artifactId>
      <version>0.2-SNAPSHOT</version>
    </dependency>

It is hosted in oss.sonatype.org repository, so it is necessary to add the repository:

   <repository>
     <id>browserid-snapshots</id>
     <name>browserid-snapshots</name>
     <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
   </repository>

Example

Eventually it is going to be in Maven Central Repository.

  

2. Use it

In the server side:

final Verifier verifier = new Verifier()
final BrowserIDResponse loginRepsonse = verifier.verify(assertion, audience);
final Status status = loginRepsonse.getStatus();
if (status == Status.OK) {
  HttpSession session = request.getSession(true);
  session.setAttribute("email", email);
  //...
}  else {
  log.info("Sign in failed...");
  //...
}

Example

  

In the client side:

<button type="button" onclick="navigator.id.request();" >Sign in - Sign up</button>
<button type="button" onclick="navigator.id.logout();" >Sign out</button>
....
	<script src="https://login.persona.org/include.js"></script>

	<script type="text/javascript">
		var currentUser = '${sessionScope.email}';
		if(!currentUser) {
			/* If falsy set it to the literal null */
			currentUser = null;
		}

		navigator.id.watch({
			loggedInUser : currentUser,
			onlogin : function(assertion) {				
				loginRequest = $.ajax({
					type : 'POST',
					url : 'in',
					data : {
						assertion : assertion
					}
				});
				loginRequest.done(function(res, status, xhr) {
					window.location.reload();
				});
				loginRequest.fail(function(xhr, status, error) {
					navigator.id.logout();
					alert("Login error: " + error);
				});
			},

			onlogout : function() {
				logoutRequest = $.ajax({
					type : 'POST',
					url : 'out'
				});
				logoutRequest.done(function(res, status, xhr) {
					window.location.reload();
				});
				logoutRequest.fail(function(xhr, status, error) {
					alert("Logout error: " + error);
				});
			}

		});
	</script>

Example

This project is based in code from https://github.com/mozilla/browserid-cookbook

About

Simple Java BrowserID Verifier

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages