-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Change Log | ||
|
||
## [1.0.0](https://github.com/auth0/lock/tree/1.0.0) (2016-10-25) | ||
[Full Changelog](https://github.com/auth0/lock/tree/1.0.0) | ||
|
||
Java library with focus on Android that provides Json Web Token (JWT) decoding. | ||
|
||
## Install | ||
The library is be available both in Maven Central and JCenter. To start using it add this line to your `build.gradle` dependencies file: | ||
|
||
```groovy | ||
compile 'com.auth0.android:jwtdecode:1.0.0' | ||
``` | ||
|
||
## Usage | ||
|
||
Decode a JWT token | ||
|
||
```java | ||
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"; | ||
JWT jwt = new JWT(token); | ||
``` | ||
|
||
A `DecodeException` will raise with a detailed message if the token has: | ||
* An invalid part count. | ||
* A part not encoded as Base64 + UTF-8. | ||
* A Header or Payload without a valid JSON format. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ allprojects { | |
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
delete 'CHANGELOG.md.release' | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,16 @@ install { | |
} | ||
} | ||
developers { | ||
developer { | ||
id 'auth0' | ||
name 'Auth0' | ||
email '[email protected]' | ||
} | ||
developer { | ||
id 'lbalmaceda' | ||
name 'Luciano Balmaceda' | ||
email '[email protected]' | ||
} | ||
developer { | ||
id 'hzalaz' | ||
name 'Hernan Zalazar' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import java.text.SimpleDateFormat | ||
|
||
apply plugin: ReleasePlugin | ||
|
||
class Semver { | ||
String version | ||
def snapshot | ||
|
||
def getStringVersion() { | ||
return snapshot ? "$version-SNAPSHOT" : version | ||
} | ||
|
||
def nextPatch() { | ||
def parts = version.split("\\.") | ||
def patch = Integer.parseInt(parts[2]) + 1 | ||
return "${parts[0]}.${parts[1]}.${patch}" | ||
} | ||
|
||
def nextMinor() { | ||
def parts = version.split("\\.") | ||
def minor = Integer.parseInt(parts[1]) + 1 | ||
return "${parts[0]}.${minor}.0" | ||
} | ||
|
||
} | ||
|
||
class ChangeLogTask extends DefaultTask { | ||
|
||
def current | ||
def next | ||
|
||
@TaskAction | ||
def update() { | ||
def repository = project.oss.library | ||
def file = new File('CHANGELOG.md') | ||
def output = new File('CHANGELOG.md.release') | ||
output.newWriter().withWriter { writer -> | ||
|
||
file.eachLine { line, number -> | ||
if (number == 0 && !line.startsWith('# Change Log')) { | ||
throw new GradleException('Change Log file is not properly formatted') | ||
} | ||
|
||
writer.println(line) | ||
|
||
if (number == 0 || number > 1) { | ||
return | ||
} | ||
|
||
def formatter = new SimpleDateFormat('yyyy-MM-dd') | ||
writer.println() | ||
writer.println("## [${next}](https://github.com/auth0/${repository}/tree/${next}) (${formatter.format(new Date())})") | ||
writer.println("[Full Changelog](https://github.com/auth0/${repository}/compare/${current}...${next})") | ||
def command = ["curl", "https://webtask.it.auth0.com/api/run/wt-hernan-auth0_com-0/oss-changelog.js?webtask_no_cache=1&repo=${repository}&milestone=${next}", "-f", "-s", "-H", "Accept: text/markdown"] | ||
def content = command.execute() | ||
content.consumeProcessOutputStream(writer) | ||
if (content.waitFor() != 0) { | ||
throw new GradleException("Failed to request changelog for version ${next}") | ||
} | ||
} | ||
} | ||
file.delete() | ||
output.renameTo('CHANGELOG.md') | ||
} | ||
} | ||
|
||
class ReleaseTask extends DefaultTask { | ||
|
||
def tagName | ||
|
||
@TaskAction | ||
def perform() { | ||
def path = project.getRootProject().getProjectDir().path | ||
project.exec { | ||
commandLine 'git', 'add', 'README.md' | ||
workingDir path | ||
} | ||
project.exec { | ||
commandLine 'git', 'add', 'CHANGELOG.md' | ||
workingDir path | ||
} | ||
project.exec { | ||
commandLine 'git', 'commit', '-m', "Release ${tagName}" | ||
workingDir path | ||
} | ||
project.exec { | ||
commandLine 'git', 'tag', "${tagName}" | ||
workingDir path | ||
} | ||
} | ||
} | ||
|
||
class ReadmeTask extends DefaultTask { | ||
|
||
def current | ||
def next | ||
|
||
final filename = 'README.md' | ||
|
||
@TaskAction | ||
def update() { | ||
def file = new File(filename) | ||
def updated = "compile '${project.group}:${project.name}:${next}'" | ||
def oldSingleQuote = "compile '${project.group}:${project.name}:${current}'" | ||
def oldDoubleQuote = "compile \"${project.group}:${project.name}:${current}\"" | ||
def contents = file.getText('UTF-8') | ||
contents = contents.replace(oldSingleQuote, updated).replace(oldDoubleQuote, updated) | ||
file.write(contents, 'UTF-8') | ||
} | ||
} | ||
|
||
class Auth0ReleasePluginExtension { | ||
String library | ||
} | ||
|
||
class ReleasePlugin implements Plugin<Project> { | ||
void apply(Project target) { | ||
def semver = current() | ||
target.extensions.create('oss', Auth0ReleasePluginExtension) | ||
target.version = semver.stringVersion | ||
def version = semver.version | ||
def nextMinor = semver.nextMinor() | ||
def nextPatch = semver.nextPatch() | ||
target.task('changelogMinor', type: ChangeLogTask) { | ||
current = version | ||
next = nextMinor | ||
} | ||
target.task('changelogPatch', type: ChangeLogTask) { | ||
current = version | ||
next = nextPatch | ||
} | ||
target.task('readmeMinor', type: ReadmeTask, dependsOn: 'changelogMinor') { | ||
current = version | ||
next = nextMinor | ||
} | ||
target.task('readmePatch', type: ReadmeTask, dependsOn: 'changelogPatch') { | ||
current = version | ||
next = nextPatch | ||
} | ||
target.task('releaseMinor', type: ReleaseTask, dependsOn: 'readmeMinor') { | ||
tagName = nextMinor | ||
} | ||
target.task('releasePatch', type: ReleaseTask, dependsOn: 'readmePatch') { | ||
tagName = nextPatch | ||
} | ||
} | ||
|
||
static def current() { | ||
def current = describeGit(false) | ||
def snapshot = current == null | ||
if (snapshot) { | ||
current = describeGit(snapshot, '0.0.1') | ||
} | ||
return new Semver(snapshot: snapshot, version: current) | ||
} | ||
|
||
static def describeGit(boolean snapshot, String defaultValue = null) { | ||
def command = ['git', 'describe', '--tags', (snapshot ? '--abbrev=0' : '--exact-match')].execute() | ||
def stdout = new ByteArrayOutputStream() | ||
def errout = new ByteArrayOutputStream() | ||
command.consumeProcessOutput(stdout, errout) | ||
if (command.waitFor() != 0) { | ||
Logging.getLogger(ReleasePlugin.class).debug(errout.toString()) | ||
return defaultValue | ||
} | ||
if (stdout.toByteArray().length > 0) { | ||
return stdout.toString().replace('\n', "") | ||
} | ||
|
||
return defaultValue | ||
} | ||
} |