@@ -6,32 +6,17 @@ import (
6
6
"time"
7
7
8
8
"github.com/oidc-mytoken/api/v0"
9
- "github.com/oidc-mytoken/server/shared/httpClient"
10
9
)
11
10
12
- func (my * MytokenProvider ) GetMytoken (req interface {}) (string , error ) {
13
- resp , err := httpClient .Do ().R ().SetBody (req ).SetResult (& api.MytokenResponse {}).SetError (& api.Error {}).Post (my .MytokenEndpoint )
14
- if err != nil {
15
- return "" , newMytokenErrorFromError ("error while sending http request" , err )
16
- }
17
- if e := resp .Error (); e != nil {
18
- if errRes := e .(* api.Error ); errRes != nil && errRes .Error != "" {
19
- return "" , & MytokenError {
20
- err : errRes .Error ,
21
- errorDetails : errRes .ErrorDescription ,
22
- }
23
- }
24
- }
25
- stRes , ok := resp .Result ().(* api.MytokenResponse )
26
- if ! ok {
27
- return "" , & MytokenError {
28
- err : "unexpected response from mytoken server" ,
29
- }
11
+ func (my * MytokenServer ) GetMytoken (req interface {}) (string , error ) {
12
+ var resp api.MytokenResponse
13
+ if err := doHTTPRequest ("POST" , my .MytokenEndpoint , req , & resp ); err != nil {
14
+ return "" , err
30
15
}
31
- return stRes .Mytoken , nil
16
+ return resp .Mytoken , nil
32
17
}
33
18
34
- func (my * MytokenProvider ) GetMytokenByMytoken (mytoken , issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string ) (string , error ) {
19
+ func (my * MytokenServer ) GetMytokenByMytoken (mytoken , issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string ) (string , error ) {
35
20
req := api.MytokenFromMytokenRequest {
36
21
GeneralMytokenRequest : api.GeneralMytokenRequest {
37
22
Issuer : issuer ,
@@ -42,12 +27,12 @@ func (my *MytokenProvider) GetMytokenByMytoken(mytoken, issuer string, restricti
42
27
Name : name ,
43
28
ResponseType : responseType ,
44
29
},
45
- Mytoken : mytoken ,
30
+ Mytoken : mytoken ,
46
31
}
47
32
return my .GetMytoken (req )
48
33
}
49
34
50
- func (my * MytokenProvider ) GetMytokenByTransferCode (transferCode string ) (string , error ) {
35
+ func (my * MytokenServer ) GetMytokenByTransferCode (transferCode string ) (string , error ) {
51
36
req := api.ExchangeTransferCodeRequest {
52
37
GrantType : api .GrantTypeTransferCode ,
53
38
TransferCode : transferCode ,
@@ -61,7 +46,7 @@ type PollingCallbacks struct {
61
46
End func ()
62
47
}
63
48
64
- func (my * MytokenProvider ) GetMytokenByAuthorizationFlow (issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string , callbacks PollingCallbacks ) (string , error ) {
49
+ func (my * MytokenServer ) GetMytokenByAuthorizationFlow (issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string , callbacks PollingCallbacks ) (string , error ) {
65
50
authRes , err := my .InitAuthorizationFlow (issuer , restrictions , capabilities , subtokenCapabilities , responseType , name )
66
51
if err != nil {
67
52
return "" , err
@@ -76,7 +61,7 @@ func (my *MytokenProvider) GetMytokenByAuthorizationFlow(issuer string, restrict
76
61
return tok , err
77
62
}
78
63
79
- func (my * MytokenProvider ) InitAuthorizationFlow (issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string ) (* api.AuthCodeFlowResponse , error ) {
64
+ func (my * MytokenServer ) InitAuthorizationFlow (issuer string , restrictions api.Restrictions , capabilities , subtokenCapabilities api.Capabilities , responseType , name string ) (* api.AuthCodeFlowResponse , error ) {
80
65
req := api.AuthCodeFlowRequest {
81
66
OIDCFlowRequest : api.OIDCFlowRequest {
82
67
GeneralMytokenRequest : api.GeneralMytokenRequest {
@@ -88,32 +73,18 @@ func (my *MytokenProvider) InitAuthorizationFlow(issuer string, restrictions api
88
73
Name : name ,
89
74
ResponseType : responseType ,
90
75
},
91
- OIDCFlow : api .OIDCFlowAuthorizationCode ,
76
+ OIDCFlow : api .OIDCFlowAuthorizationCode ,
92
77
},
93
78
RedirectType : "native" ,
94
79
}
95
- resp , err := httpClient .Do ().R ().SetBody (req ).SetResult (& api.AuthCodeFlowResponse {}).SetError (& api.Error {}).Post (my .MytokenEndpoint )
96
- if err != nil {
97
- return nil , newMytokenErrorFromError ("error while sending http request" , err )
98
- }
99
- if e := resp .Error (); e != nil {
100
- if errRes := e .(* api.Error ); errRes != nil && errRes .Error != "" {
101
- return nil , & MytokenError {
102
- err : errRes .Error ,
103
- errorDetails : errRes .ErrorDescription ,
104
- }
105
- }
106
- }
107
- authRes , ok := resp .Result ().(* api.AuthCodeFlowResponse )
108
- if ! ok {
109
- return nil , & MytokenError {
110
- err : unexpectedResponse ,
111
- }
80
+ var resp api.AuthCodeFlowResponse
81
+ if err := doHTTPRequest ("POST" , my .MytokenEndpoint , req , & resp ); err != nil {
82
+ return nil , err
112
83
}
113
- return authRes , nil
84
+ return & resp , nil
114
85
}
115
86
116
- func (my * MytokenProvider ) Poll (res api.PollingInfo , callback func (int64 , int )) (string , error ) {
87
+ func (my * MytokenServer ) Poll (res api.PollingInfo , callback func (int64 , int )) (string , error ) {
117
88
expires := time .Now ().Add (time .Duration (res .PollingCodeExpiresIn ) * time .Second )
118
89
interval := res .PollingInterval
119
90
if interval == 0 {
@@ -139,7 +110,7 @@ func (my *MytokenProvider) Poll(res api.PollingInfo, callback func(int64, int))
139
110
return "" , fmt .Errorf ("polling code expired" )
140
111
}
141
112
142
- func (my * MytokenProvider ) PollOnce (pollingCode string ) (string , bool , error ) {
113
+ func (my * MytokenServer ) PollOnce (pollingCode string ) (string , bool , error ) {
143
114
req := api.PollingCodeRequest {
144
115
GrantType : api .GrantTypePollingCode ,
145
116
PollingCode : pollingCode ,
0 commit comments