-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 119e576
Showing
13 changed files
with
1,202 additions
and
0 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,8 @@ | ||
version = 1 | ||
|
||
[[analyzers]] | ||
name = "go" | ||
enabled = true | ||
|
||
[analyzers.meta] | ||
import_paths = ["github.com/oidc-mytoken/lib"] |
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,3 @@ | ||
/.idea/ | ||
tags | ||
dist/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020-2021 Gabriel Zachmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,19 @@ | ||
![mytoken logo](https://git.scc.kit.edu/oidc/mytoken/-/raw/master/docs/img/mytoken.png) | ||
|
||
[![License](https://img.shields.io/github/license/oidc-mytoken/lib.svg)](https://github.com/oidc-mytoken/lib/blob/master/LICENSE) | ||
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/oidc-mytoken/lib) | ||
[![Go Report](https://goreportcard.com/badge/github.com/oidc-mytoken/lib)](https://goreportcard.com/report/github.com/oidc-mytoken/lib) | ||
[![DeepSource](https://deepsource.io/gh/oidc-mytoken/lib.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/oidc-mytoken/lib/?ref=repository-badge) | ||
[![Release date](https://img.shields.io/github/release-date/oidc-mytoken/lib.svg)](https://github.com/oidc-mytoken/lib/releases/latest) | ||
[![Release version](https://img.shields.io/github/release/oidc-mytoken/lib.svg)](https://github.com/oidc-mytoken/lib/releases/latest) | ||
|
||
# mytokenlib | ||
|
||
`mytokenlib` is a go library for communicating with amytoken server. | ||
`mytoken` is a central web service with the goal to easily obtain OpenID Connect access tokens across devices. | ||
|
||
A mytoken command line client can be found at [https://github.com/oidc-mytoken/client](https://github.com/oidc-mytoken/client). | ||
|
||
The mytoken server can be found at [https://github.com/oidc-mytoken/server](https://github.com/oidc-mytoken/server). | ||
|
||
A demo instance of mytoken is running at [https://mytoken.data.kit.edu/](https://mytoken.data.kit.edu/). |
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,29 @@ | ||
package mytokenlib | ||
|
||
import ( | ||
"github.com/oidc-mytoken/server/pkg/api/v0" | ||
"github.com/oidc-mytoken/server/shared/httpClient" | ||
) | ||
|
||
func (my *MytokenProvider) GetAccessToken(mytoken, oidcIssuer string, scopes, audiences []string, comment string) (string, error) { | ||
req := NewAccessTokenRequest(oidcIssuer, mytoken, scopes, audiences, comment) | ||
resp, err := httpClient.Do().R().SetBody(req).SetResult(&api.AccessTokenResponse{}).SetError(&api.APIError{}).Post(my.AccessTokenEndpoint) | ||
if err != nil { | ||
return "", newMytokenErrorFromError("error while sending http request", err) | ||
} | ||
if e := resp.Error(); e != nil { | ||
if errRes := e.(*api.APIError); errRes != nil && errRes.Error != "" { | ||
return "", &MytokenError{ | ||
err: errRes.Error, | ||
errorDetails: errRes.ErrorDescription, | ||
} | ||
} | ||
} | ||
atRes, ok := resp.Result().(*api.AccessTokenResponse) | ||
if !ok { | ||
return "", &MytokenError{ | ||
err: unexpectedResponse, | ||
} | ||
} | ||
return atRes.AccessToken, nil | ||
} |
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,25 @@ | ||
package mytokenlib | ||
|
||
// MytokenError is a error type from the mytoken library | ||
type MytokenError struct { | ||
err string | ||
errorDetails string | ||
} | ||
|
||
func (err *MytokenError) Error() string { | ||
e := err.err | ||
if err.errorDetails != "" { | ||
e += ": " + err.errorDetails | ||
} | ||
return e | ||
} | ||
|
||
func newMytokenErrorFromError(e string, err error) *MytokenError { | ||
return &MytokenError{ | ||
err: e, | ||
errorDetails: err.Error(), | ||
} | ||
} | ||
|
||
const unexpectedResponse = "unexpected response from mytoken server" | ||
const errorWhileHttp = "error while sending http request" |
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,5 @@ | ||
module github.com/oidc-mytoken/lib | ||
|
||
go 1.13 | ||
|
||
require github.com/oidc-mytoken/server v0.1.1-0.20210408094857-353b733d8e2b |
Oops, something went wrong.