Created
September 18, 2020 23:48
-
-
Save hohonuuli/1f404c037b4056fbf6b9525e8eb84b87 to your computer and use it in GitHub Desktop.
Code for a Medium article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package firebase.jwt; | |
import java.util.Optional; | |
public class AuthHeader { | |
private final String type; | |
private final String token; | |
public AuthHeader(String type, String token) { | |
this.type = type; | |
this.token = token; | |
} | |
public String getType() { | |
return type; | |
} | |
public String getToken() { | |
return token; | |
} | |
public static Optional<AuthHeader> parse(String authentication) { | |
var opt = Optional.<AuthHeader>empty(); | |
if (authentication != null) { | |
var parts = authentication.split("\\s+"); | |
if (parts.length == 2) { | |
var auth = new AuthHeader(parts[0].trim(), parts[1].trim()); | |
opt = Optional.of(auth); | |
} | |
} | |
return opt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment