22
22
import net .ymate .framework .webmvc .support .UserSessionBean ;
23
23
import net .ymate .module .oauth .IOAuth ;
24
24
import net .ymate .module .oauth .OAuth ;
25
- import net .ymate .module .oauth .OAuthCode ;
26
25
import net .ymate .module .oauth .intercept .SnsAccessTokenCheckInterceptor ;
27
26
import net .ymate .module .oauth .support .OAuthResponseUtils ;
28
27
import net .ymate .platform .core .beans .annotation .Before ;
@@ -96,23 +95,7 @@ public IView authorize(@RequestParam(defaultValue = "false") Boolean authorized)
96
95
.setParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_STATE , _state )
97
96
.buildQueryMessage ();
98
97
} else {
99
- switch (_responseType ) {
100
- case CODE :
101
- OAuthCode _authzCode = _authzHelper .createOrUpdateAuthCode (_redirectURI , _scope );
102
- //
103
- _response = OAuthASResponse .authorizationResponse (_request , HttpServletResponse .SC_FOUND )
104
- .location (_redirectURI )
105
- .setCode (_authzCode .getCode ())
106
- .setParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_STATE , _state )
107
- .buildQueryMessage ();
108
- break ;
109
- case TOKEN :
110
- IOAuth .IOAuthTokenHelper _tokenHelper = OAuth .get ().tokenHelper (_oauthRequest .getClientId (), _oauthRequest .getClientSecret (), _oauthRequest .getParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_CODE ), _uid );
111
- _response = OAuthResponseUtils .tokenToResponse (_tokenHelper .createOrUpdateAccessToken (), _state );
112
- break ;
113
- default :
114
- _response = OAuthResponseUtils .badRequest (OAuthError .CodeResponse .UNSUPPORTED_RESPONSE_TYPE );
115
- }
98
+ _response = __parseResponseType (_request , _responseType , _authzHelper , _oauthRequest , _redirectURI , _scope , _uid , _state );
116
99
}
117
100
} else {
118
101
_response = OAuthResponseUtils .badRequest (OAuthError .TokenResponse .INVALID_REQUEST );
@@ -126,13 +109,7 @@ public IView authorize(@RequestParam(defaultValue = "false") Boolean authorized)
126
109
.addAttribute ("client_icon" , _authzHelper .getOAuthClient ().getIconUrl ())
127
110
.addAttribute ("client_domain" , _authzHelper .getOAuthClient ().getDomain ());
128
111
} else {
129
- OAuthCode _authzCode = _authzHelper .createOrUpdateAuthCode (_redirectURI , _scope );
130
- //
131
- _response = OAuthASResponse .authorizationResponse (_request , HttpServletResponse .SC_FOUND )
132
- .location (_redirectURI )
133
- .setCode (_authzCode .getCode ())
134
- .setParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_STATE , _state )
135
- .buildQueryMessage ();
112
+ _response = __parseResponseType (_request , _responseType , _authzHelper , _oauthRequest , _redirectURI , _scope , _uid , _state );
136
113
}
137
114
}
138
115
return View .httpStatusView (_response .getResponseStatus ()).addHeader ("Location" , _response .getLocationUri ());
@@ -148,6 +125,25 @@ public IView authorize(@RequestParam(defaultValue = "false") Boolean authorized)
148
125
return WebUtils .buildErrorView (WebContext .getContext ().getOwner (), 0 , _response .getBody ());
149
126
}
150
127
128
+ private OAuthResponse __parseResponseType (HttpServletRequest request , ResponseType _responseType , IOAuth .IOAuthAuthzHelper _authzHelper , OAuthAuthzRequest _oauthRequest , String _redirectURI , String _scope , String uid , String state ) throws Exception {
129
+ OAuthResponse _response ;
130
+ switch (_responseType ) {
131
+ case CODE :
132
+ _response = OAuthASResponse .authorizationResponse (request , HttpServletResponse .SC_FOUND )
133
+ .location (_redirectURI )
134
+ .setCode (_authzHelper .createOrUpdateAuthCode (_redirectURI , _scope ).getCode ())
135
+ .setParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_STATE , state )
136
+ .buildQueryMessage ();
137
+ break ;
138
+ case TOKEN :
139
+ _response = OAuthResponseUtils .tokenToResponse (OAuth .get ().tokenHelper (_oauthRequest .getClientId (), _oauthRequest .getClientSecret (), _oauthRequest .getParam (org .apache .oltu .oauth2 .common .OAuth .OAUTH_CODE ), uid ).createOrUpdateAccessToken (), state );
140
+ break ;
141
+ default :
142
+ _response = OAuthResponseUtils .badRequest (OAuthError .CodeResponse .UNSUPPORTED_RESPONSE_TYPE );
143
+ }
144
+ return _response ;
145
+ }
146
+
151
147
/**
152
148
* @return 返回访问凭证 (grant_type=[authorization_code|password])
153
149
* @throws Exception 可能产生的任何异常
0 commit comments