-
Notifications
You must be signed in to change notification settings - Fork 128
Added JWT identity for ios and android #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
13ae8d7
4fe30a3
5eab349
f865bac
33f1df1
e2e209c
6596504
fc26a68
4856c1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #Thu Oct 29 18:09:13 CET 2020 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super convinced these gradle/gradle-wrapper files are necessary for a library. Did you mean to commit them? |
||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.taskrabbit.zendesk; | ||
|
|
||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import okhttp3.Call; | ||
| import okhttp3.Callback; | ||
| import okhttp3.MediaType; | ||
| import okhttp3.OkHttpClient; | ||
| import okhttp3.Request; | ||
| import okhttp3.RequestBody; | ||
| import okhttp3.Response; | ||
| import zendesk.chat.JwtAuthenticator; | ||
|
|
||
| class JwtAuth implements JwtAuthenticator { | ||
| private String alfZendeskJwtUrl; | ||
|
|
||
| OkHttpClient client = new OkHttpClient(); | ||
| final MediaType JSON = MediaType.get("application/json; charset=utf-8"); | ||
|
|
||
| JwtAuth(String alfZendeskJwtUrl) { | ||
| this.alfZendeskJwtUrl = alfZendeskJwtUrl; | ||
| } | ||
|
|
||
| private void retrieveToken(final JwtCallback callback) throws IOException { | ||
|
|
||
| RequestBody body = RequestBody.create(JSON, "{}"); | ||
| Request request = new Request.Builder() | ||
| .url(alfZendeskJwtUrl) | ||
| .post(body) | ||
| .build(); | ||
| client.newCall(request).enqueue(new Callback() { | ||
| @Override | ||
| public void onFailure( Call call, IOException e) { | ||
| e.printStackTrace(); | ||
| callback.onError(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResponse( Call call, Response response) throws IOException { | ||
| String jsonData = response.body().string(); | ||
| try { | ||
| JSONObject Jobject = new JSONObject(jsonData); | ||
| String zendesk_jwt = (String) Jobject.get("jwt"); | ||
|
|
||
| callback.onSuccess(zendesk_jwt); | ||
|
|
||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| callback.onError(); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void getToken(final JwtCompletion jwtCompletion) { | ||
| try { | ||
| retrieveToken(new JwtCallback() { | ||
| @Override | ||
| public void onSuccess(String token) { | ||
| jwtCompletion.onTokenLoaded(token); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError() { | ||
| jwtCompletion.onError(); | ||
| } | ||
| }); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| interface JwtCallback { | ||
| void onSuccess(String token); | ||
|
|
||
| void onError(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.